Frontend development

Stage 2 · Lesson 10 of 10

ES modules

JavaScript and the browser

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

  • CoursePaid
    Grokking JavaScript Fundamentals

    Design Gurus · Beginner · $50

    Guided beginner course on the language core, with quizzes after every chapter

  • GuideFree
    JavaScript.info

    Ilya Kantor

    Free and thorough: Part 1 for the language, Part 2 for the DOM and events, Part 3 for fetch

Practise

  • Thirty small browser projects with no framework to hide behind

  • Free JavaScript curriculum exercises for daily reps on the language core

Keep handy

  • JavaScript and Web API reference, including fetch, the DOM and events

Also worth your time

Mark this stage as not done?