Course contentsShow
← JavaScript
Lesson 1410 of 2,72331. ModulesFree lesson

Importing Named Exports

Understand how to import specific named exports using curly braces and the import statement.

Importing Named Exports

You'll learn how to selectively bring named exports from other modules into your code using curly braces and the import statement.

What Are You Actually Doing?

When a module exports specific named values (functions, variables, classes), you can import exactly what you need using the import statement with curly braces. This is like ordering specific items from a menu rather than getting everything the kitchen offers.

The syntax mirrors the export syntax but works in reverse:

import { functionName, variableName } from './module.js';

How It Works

The curly braces { } tell JavaScript you're importing specific named exports by their exact names. You must use the same names that were exported from the source module:

// math.js exports:
export const PI = 3.14159;
export function add(a, b) { return a + b; }

// app.js imports:
import { PI, add } from './math.js';

console.log(PI);        // 3.14159
console.log(add(2, 3)); // 5

You can import one or multiple named exports, separated by commas. The order doesn't matter—you can import { add, PI } or { PI, add }—but the names must match exactly.

Why This Matters

This selective importing keeps your code clean and efficient. You only bring in what you need, making dependencies explicit and avoiding namespace pollution. If a module exports ten functions but you only need two, import just those two.

Key Takeaway: Use curly braces with the import statement to selectively import specific named exports by their exact names from another module.