← Back to Roadmap

Modules (ESM)

Medium

In plain terms

ES modules use import and export. Export names or default. Import specific names or namespace. Script must have type="module". Enables code splitting and reuse.

What you need to know

  • export, import
  • Default and named exports
  • type="module"

Try it yourself

Copy the code below and run it in your browser console or a code editor:

// math.js
export const add = (a, b) => a + b;
export default function multiply(a, b) { return a * b; }

// main.js
import multiply, { add } from './math.js';
import * as math from './math.js';

Learn more

Dive deeper with these trusted resources: