JavaScript › ES Modules

How do you import everything from a module under one namespace object?

Beginner

Answer

Use import * as name from '...' to collect all of a module's named exports into a single object, accessed as name.exportedThing.
import * as MathUtils from './math.js';
console.log(MathUtils.PI);
MathUtils.default(2, 3); // calling the default export
Real-world example Importing an entire utility library under one namespace to avoid dozens of individual named imports.

Common follow-ups: Does this also include the default export, and if so, under what key?