Importing Named Exports
Import named exports using curly braces with the exact exported name. You can import multiple names in one statement.
Import named exports using curly braces with the exact exported name. You can import multiple names in one statement.
// Import specific names
import { add, multiply } from "./math.js";
console.log(add(2, 3)); // 5
console.log(multiply(4, 5)); // 20
// Import with renaming
import { add as sum, PI as pi } from "./math.js";
console.log(sum(1, 2)); // 3
console.log(pi); // 3.14159
Import only what you need — tree-shaking tools remove unused exports from production bundles.
More in JavaScript