Skip to main content
A default export is an ECMAScript Module (ESM) directive used to expose a single, primary value—such as a function, class, object, or primitive—from a module. Unlike named exports, a module can contain at most one default export. The exported value can be imported into another module without using the curly brace syntax required for named imports, and it can be bound to any arbitrary local identifier. Under the hood, a default export is syntactic sugar for a named export where the exported identifier is strictly the reserved keyword default.

Export Syntax

Default exports can be applied directly to anonymous or named declarations, applied to previously declared references, or created using the named export alias syntax. Because a module can only have one default export, the following examples represent mutually exclusive implementations. Exporting declarations directly:
Exporting references, expressions, and aliases:
Note: You cannot use export default directly with variable declarations (const, let, var) on the same line. The declaration and the export must be separated.

Import Syntax

When statically importing a default export, the receiving module dictates the identifier name. The JS engine resolves the default binding from the source module and assigns it to the provided local identifier.
The above syntax is functionally identical to importing the default keyword as a named import and aliasing it:
Note: While named imports use curly braces, they are strictly a distinct static binding syntax and not object destructuring. For example, named imports use the as keyword for aliasing (import { default as ServerConfig } from './config.js'), whereas object destructuring uses a colon (const { default: ServerConfig } = obj).

Dynamic Imports

When loading modules asynchronously using dynamic imports (await import()), the default export is not returned directly. Instead, the promise resolves to a module namespace object. The default export must be accessed via the .default property on this resolved object.

Combining Default and Named Exports

A single module can utilize both one default export and multiple named exports. Exporting:
Importing: The default import must precede the named imports in the syntax.

Re-exporting a Default Export

A default export can be aggregated and re-exported from a central module (often an index.js file). To pass through the default export of another module as the default export of the current module:
To pass through the default export of another module as a named export of the current module:
Tired of Poor JavaScript Skills? Fix That With Deep Grasping!Learn More