Skip to main content

JavaScript Modules

6 lessonsAbout 36 minutesAdvanced

This part of the JavaScript Tutorial runs from JavaScript Modules through to JavaScript Module Patterns. There are 6 lessons here, and working through them takes about 36 minutes at a steady pace.

It follows on from JavaScript Storage & BOM, so finish that first if you have not already — the examples below assume you are comfortable with it.

Each lesson below says what it covers before you open it. Read them in order the first time; afterwards this page works as a index you can jump back into when you need to check one thing.

  1. 1JavaScript ModulesA module is a file that can export values for other files to import.
  2. 2JavaScript exportexport makes a function, variable or class available to other modules.
  3. 3JavaScript importimport brings an exported value from another module into the current file.
  4. 4JavaScript Module ScriptsA script becomes a module by adding type="module" to its tag.
  5. 5JavaScript Dynamic Importimport() loads a module while the program is running, returning a promise.
  6. 6JavaScript Module PatternsBefore real modules existed, JavaScript used closures to fake the same isolation.