Language concepts
export declaration
Publishes bindings or a default export from an ES module. A module cannot declare duplicate export names. The consumer resolves a binding by its exported name. Multi-file example: save each listed file separately, then run the entry file with Node.js. See the packaged fixture for the original files.
Formal Syntax & Structure
javascript syntaxjavascript
export { local as publicName };export default expression;Working Example
Example Snippetjavascript
// File: math.mjsconst rate = 3;export { rate as unitRate };export default function total(n) { return n * rate; }
// File: main.mjsimport total, { unitRate } from "./math.mjs";console.log(unitRate, total(4));