Stage 2 · Lesson 10 of 10
ES modules
Modules split code into files that share only what they . Write export const formatPrice = ... in one file and import { formatPrice } from "./format.js" in another. A default export is imported without the curly braces.
Each module has its own scope, so nothing leaks into the global scope, and it runs only once however many files import it. In the browser you load a module with <script type="module">. In practice, a such as , which comes in the next stage, your modules and npm together. Every framework project is organised with ES modules.
Common trapcircular imports, where two files import each other and one sees the other only half set up; keep dependencies flowing one way.
A question to check yourself, an AI practice session and 1 cheat sheet entry come with the full roadmap. Unlock
Resources for this stage
Start with· follow one of these
- CoursePaidGrokking JavaScript Fundamentals
Design Gurus · Beginner · $50
Guided beginner course on the language core, with quizzes after every chapter
- GuideFreeJavaScript.info
Ilya Kantor
Free and thorough: Part 1 for the language, Part 2 for the DOM and events, Part 3 for fetch
Practise
Keep handy
Also worth your time
- You Don't Know JS YetGo deeper
For when scope, this, coercion or async behaviour still feel like magic