What's the difference between a named export and a default export?
Short answer
A module can have any number of named exports (imported with matching names in curly braces), but at most one default export (imported with any name you choose, no braces required).
Advertisement
AModel answer
A module can have any number of named exports (imported with matching names in curly braces), but at most one default export (imported with any name you choose, no braces required).
// math.js
export const PI = 3.14;
export default function add(a, b) { return a + b; }
// main.js
import add, { PI } from './math.js';Real-world example
Using a default export for a component's main class/function, and named exports for its helper utilities.
Likely follow-ups
- Can a module have both a default export and named exports at the same time?
Related topics