Split code across files with ES modules — named exports, default exports, namespace imports, and dynamic import().
Why: ES modules are the standard for splitting code across files. Named exports let you export multiple things; a default export is the primary export of a file.
// ── math.js ──────────────────────────────────────────
// export function add(a, b) { return a + b; }
// export function multiply(a, b) { return a * b; }
// export const PI = 3.14159;
// export default function main() { ... } // one per file
// ── main.js ───────────────────────────────────────────
// Named imports
// import { add, multiply, PI } from './math.js';
// Rename on import
// import { add as sum } from './math.js';
// Namespace import
// import * as math from './math.js';
// console.log(math.add(1, 2));
// Default import
// import main from './math.js';
// Dynamic import — returns a Promise, works anywhere
// const { add } = await import('./math.js');
// Re-export
// export { add } from './math.js';
console.log('ESM: import/export — static, hoisted');
console.log('Dynamic: import() — async, lazy loading');
console.log('Always strict mode in ES modules');