export
Exposes bindings from an ES module so other modules can import them.
Syntax
export const name = value;
export function fn() {}
export { a, b as c };
export default expression;
Examples
// math.js
export function add(a, b) {
return a + b;
}
export const PI = 3.14159;
// greet.js — default export
export default function greet(name) {
return "Hello, " + name;
}
// re-export from another module
export { add, PI } from "./math.js";
Notes
- A module may have any number of named exports but at most one default
export.
- Exported bindings are live; importers see later reassignments.
- `export` statements must appear at the top level of a module.
Browser & runtime support
| Environment | Since version |
|---|---|
| chrome | 61 |
| firefox | 60 |
| safari | 10.1 |
| edge | 16 |
| node | 12.0 |