A namespace export is an ECMAScript module (ESM) syntax that aggregates all named exports from a specified module and re-exports them as properties of a single Module Namespace Object under a new identifier.Documentation Index
Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
Use this file to discover all available pages before exploring further.
Technical Mechanics
When the JavaScript engine encounters a namespace export, it performs the following operations:- Resolution: It resolves the target module specifier (
'./module-path.js'). - Aggregation: It collects all exported bindings (variables, functions, classes) from the target module.
- Object Creation: It constructs a Module Namespace Object (
[object Module]). - Re-exportation: It exports this newly created namespace object from the current module using the specified
identifierName.
Live Bindings vs. Immutability
The generated Module Namespace Object is structurally immutable—it is sealed, and its properties cannot be added, removed, or reassigned. However, ESM utilizes live bindings. The properties on the namespace object are not static copies of values; they are direct references to the bindings in the source module. If the source module mutates an underlying exported variable, the value returned by the namespace object’s property will dynamically update to reflect that change.Scope and Local Bindings
Crucially, a namespace export does not import the bindings into the current module’s local scope. This behavior distinguishesexport * as ... from a two-step import-then-export process. The statement import * as MathUtils from './math.js'; export { MathUtils }; creates a local MathUtils variable that can be accessed within the module. In contrast, export * as MathUtils from './math.js'; performs the re-export directly without polluting the local scope. You cannot access the aggregated properties within the file performing the export.
Execution Example
Given a source module with multiple named exports and a mutable variable:Default Export Behavior
If the target module contains adefault export, the namespace export includes it as a property explicitly named default on the resulting Module Namespace Object.
Master JavaScript with Deep Grasping Methodology!Learn More





