freecoding.school100% FREE · NO SIGNUP
Closure CavesISSUE #53 of 61

modules · default vs named

LambdaVSThe Mutator
Lambda saysModules export named bindings or one default — import syntax differs for each.

Named exports (export const x) are imported by name in braces and can be many per file. A export default is the module's single main value, imported without braces and renamable freely. Mixing both is fine. Named exports aid tree-shaking and discoverability; defaults suit a module's one obvious thing.

Power-ups you unlock

The Mutator attacks — common mistakes

Boss battleWrite a module with one default export and one named export, and import both.

Example code

<!doctype html><html><head><meta charset="utf-8"></head>
<body style="background:#06040d;color:#e6e0ff;font-family:monospace;padding:20px"><pre>// utils.js
export default function main(){}
export const VERSION = '1.0';

// app.js
import main, { VERSION } from './utils.js';</pre></body></html>
▶ Open the interactive comic issue
‹ Modules · Import · ExportDynamic Import · Code Splitting ›