Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community!
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.Start your free trial
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,647 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,