SyntaxStudy
Sign Up
JavaScript Intermediate 4 min read

ES Modules

ES Modules

ES modules use export and import to share code between files with static analysis and tree-shaking support.

Example
// math.js
export const PI = 3.14;
export function add(a, b) { return a + b; }
export default class Calculator { }

// main.js
import Calculator, { PI, add } from "./math.js";
import * as Math from "./math.js";
const { PI: pi } = await import("./math.js"); // dynamic import
Pro Tip

Dynamic import() loads modules on-demand — great for code splitting and lazy loading.