From the course: JavaScript Essential Training

Unlock this course with a free trial

Join today to access over 22,600 courses taught by industry experts.

JavaScript modules

JavaScript modules

- [Instructor] As you start working with JavaScript, you'll quickly notice these files tend to get really large and kind of hard to work with. You can see here, this is a fairly straightforward script that isn't too much going on but you can already see it's getting really long. And there's a lot of pieces that rely on other pieces to be in place and figuring out how everything is wired together requires a lot of scrolling up and down. To solve this problem, we now have something called JavaScript modules. JavaScript modules allow us to break pieces out of a JavaScript file and place them in a separate file and then import them back into the original file again. In the exercise files four, 02_04, you can see this in action. So here we have script.js. And at the very top of script.js it says import backpack from backpack.js. If I opened backpack.js, you'll see here we have a constant called backpack. That's what's being…

Contents