CKTIS / JavaScript
export — exposing module elements
The export keyword exposes elements of an ECMAScript module to other modules. It supports named exports, one default export, and re-exporting from another module.
Version: ECMAScript and Web APIs; exact feature edition and browser support reviewed per entry; Node 24 in repository does not prove browser API support
Syntax
export const name = value;
export { name, name as alias };
export default expression;
export { name } from "./module.mjs";
export * from "./module.mjs";export is a reserved keyword that declares exports of an ECMAScript module. It occurs only at module top level, not inside functions or blocks. In an ordinary script, it causes a syntax error.
Declare a named export directly, for example with export const name = value;, or expose an existing declaration with export { name };. Writing export { name as alias }; changes the exported name, not the local name. These braces form an export list, not an object literal.
A module can have many named exports and at most one default. A named import uses the exported name; a default import can use any valid local name. Duplicate exported names are syntax errors. export { name } from "./module.mjs"; forwards an export, while export * from "./module.mjs"; does not forward default.
Imported bindings reflect changes made by the source module; the importer cannot assign new values to them. Beware: export default expression; exports the evaluated expression result, whereas export { name as default }; exposes the live binding name. In the example, calling increment() changes the value observed as count.
Examples
// counter.mjs
export let count = 0;
export function increment() {
count += 1;
}
export default "counter";
// main.mjs
import label, { count, increment } from "./counter.mjs";
console.log(label, count);
increment();
console.log(label, count);Result
counter 0 counter 1
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.