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

Named Export Syntax

Learn how to export multiple values from a module using the named export syntax with the export keyword.

Named Export Syntax

You'll learn how to use the export keyword to ship multiple values from a single module.

The Core Idea

In ES Modules, named export syntax is the mechanic that lets you explicitly mark which variables, functions, or classes should be available to other modules. Think of it like labeling specific items in a toolbox as "available for loan" — other modules can then request those exact items by name.

The syntax is straightforward: place the export keyword directly in front of any declaration, or use a separate export statement with curly braces.

Two Ways to Export by Name

1. Export at declaration:

export const API_KEY = 'abc123';
export function fetchData(url) {
  // implementation
}
export class User {
  // class definition
}

2. Export after declaration:

const API_KEY = 'abc123';
function fetchData(url) {
  // implementation
}
class User {
  // class definition
}

export { API_KEY, fetchData, User };

Both approaches do the same thing — they make API_KEY, fetchData, and User available for import in other modules. The second style is handy when you want to see all exports in one place, or when you're exporting values declared earlier in the file.

Why Multiple Exports Matter

Unlike systems that force you to export only one thing, named exports let you create utility modules with multiple related functions, or configuration modules with several constants. Other modules can cherry-pick exactly what they need.

Key Takeaway: Use export with curly braces or directly on declarations to export multiple named values from a module — consumers can then import exactly what they need by name.