A namespace import is an ECMAScript module (ESM) syntax that gathers all exported bindings from a specified module and attaches them as properties to a single, locally scoped object. This mechanism creates a Module Namespace Exotic Object, allowing access to a module’s entire exported API surface through a single 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.
Syntax
*: Represents all named and default exports from the target module.as namespaceIdentifier: Binds the imported Module Namespace Object to a local variable name.module-specifier: The string literal path to the module.
The Module Namespace Object
The object created by a namespace import is not a standard JavaScript object literal. It is a specialized exotic object with strict internal behaviors:- Live Bindings: Properties on the namespace object maintain a live connection to the exported variables in the source module. If the source module mutates an exported value, the namespace object immediately reflects that change.
- Property Attributes & Assignment: Exported bindings are exposed as data properties with
writable: true. This is required to satisfy core JavaScript object invariants, as the values can change over time via live bindings. However, the object utilizes a custom[[Set]]internal method that always returnsfalse. Because ES modules execute in strict mode, attempting to reassign a property throws aTypeError. - Extensibility: The namespace object is non-extensible (
Object.isExtensible()returnsfalse) and sealed (Object.isSealed()returnstrue). It is not frozen (Object.isFrozen()returnsfalseif the module has at least one export) because its exported data properties reportwritable: true. - Null Prototype: The object inherits from nothing. Evaluating
Object.getPrototypeOf(namespaceIdentifier)returnsnull. - Default Export Handling: If the source module contains a
defaultexport, it is exposed on the namespace object under the explicit property keydefault. - Symbol.toStringTag: The object has a built-in
[Symbol.toStringTag]property with the string value"Module".
Mechanical Example
Source Module (source.js):
main.js):
Master JavaScript with Deep Grasping Methodology!Learn More





