logo

Modules and Imports

How ES modules work, import/export syntax, and module resolution basics.

Short explanation

ES modules (import/export) enable modular code with explicit dependencies. Modules are loaded with defined semantics that differ from older script-based approaches.

Syntax example

// utils.js
export function format(n) {
  return n.toFixed(2);
}

// app.js
import { format } from './utils.js';
console.log(format(3.14159));

How JS handles it internally

The runtime creates module records with import and export maps, resolving dependencies and ensuring bindings are live (i.e., exports are updated if the original value changes in the module).

FAQ

Q: Are module imports static or dynamic?

A: Static imports are resolved at parse time; dynamic import() allows runtime loading of modules.