SyntaxStudy
Sign Up
JavaScript Intermediate 4 min read

Importing All Exports

Namespace Imports

Import everything a module exports as a namespace object using * as name. Access exports as properties of that object.

Example
// math.js exports: PI, add, subtract, multiply
import * as Math from "./math.js";

console.log(Math.PI);             // 3.14159
console.log(Math.add(2, 3));      // 5
console.log(Math.multiply(2, 4)); // 8

// Useful when you need many exports
// or when there is a name conflict
Pro Tip

Namespace imports disable tree-shaking for that module — prefer named imports when possible for better bundling.