Favorites

JavaScript export Statement

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee
export
JavaScript ModulesThis statement is supported by all modern browsers.
Updated 28th November 2026

The export declaration makes values, functions and classes from a JavaScript module available for other modules to import.

Description

The export declaration marks values to be shared from a module. A module can have any number of named exports, imported by their names in braces, and at most one default export, imported with any name you choose. You can export declarations directly, export a list of existing names (renaming with as), or re-export from another module with export ... from.

Exports are live bindings: if the exporting module changes an exported let variable, importers see the new value. export can only be used in modules.

Named exports are usually preferred, because the name is fixed, which makes searching and automatic refactoring easier, and a module can export several things. A default export suits modules that provide one main thing, such as a class or a component. A module can have both. Re-exporting with export * from is a common way to create a single entry point, often called a barrel file, that gathers the exports of several modules.

Syntax

export const name = value;
export function fn() {}
export default expression;
export { name1, name2 as alias };
export * from './other.js';

Example

// math.js
// export const PI = 3.14159;
// export function area(r) { return PI * r * r; }
// export default class Circle {}

// main.js
// import Circle, { area, PI as pi } from './math.js';

const src = 'export const PI = 3.14159; export function area(r) { return PI * r * r; }';
import('data:text/javascript,' + encodeURIComponent(src))
  .then(({ area, PI }) => console.log(PI, area(2).toFixed(2)));

Browser Support

The following information will show you the current browser support for the export statement. Hover over a browser icon to see the version that first introduced support for this statement.

This statement is supported by all modern browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported
☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee