Skip to main content
A side effect import is an ES6 module import declaration that executes a target module’s top-level code without binding any of its exports to the importing module’s lexical scope.
import "module-name";
import "./local-module.js";
When the JavaScript engine evaluates a side effect import, it performs the standard module resolution, fetching, and parsing phases. During the execution phase, the engine runs the target module’s code synchronously. Any mutations performed by the target module—such as modifying globalThis, extending native prototypes, or interacting with the host environment—take effect immediately in the runtime environment. Because ES modules operate as singletons within the module record map, the engine executes the side effect module exactly once per JavaScript realm. Subsequent imports of the exact same module specifier, regardless of whether they are side effect imports or standard binding imports, will reference the cached module record and bypass the execution phase. This syntax strictly isolates namespaces. The importing module receives no references to the target module’s internal declarations or exports, ensuring the local scope remains unpolluted while still triggering the target module’s initialization logic.
Tired of Poor JavaScript Skills? Fix That With Deep Grasping!Learn More