Welcome to the Treehouse Community
Looking to learn something new?
javier klijnjan5,409 Points
How does the array gets linked in the for loop?
i don't understand how we can access an array that was created in another file. In the for loop the professor calls the array "students" and stores it in a variable call "student", but the array is not created in the same file, how come?
Wiktor Bednarz18,635 Points
Before that there were bunch of other more or less messy ways of importing code from other files. However now it's more or less streamlined thank to this new ES6 functionality.
- each <script> tag sends out a HTTP request, the more of them you've got to perform, the more laggy your app is
- your code might get broken considering that all the seperate files get combined into one and that's because they all share one global scope, which before merging was split into seperate global scopes for each file
There are multiple ways of avoiding those problems, but it's way out of the scope of your question. However if you want to dig into the topic, there are some resources which I could recommend for you:
- Understanding ES6 Modules
tl;dr: The browser imports that data for you
Hope I was clear enough,