Chapter XXII · Modules

export

The `export` statement makes functions, objects, or primitive values available to other modules for importing.

01 How It Works

Think of placing finished tools on a public display shelf for other workers to borrow.

Values can be exported either as named exports or as a single default export per module file.

example.js
export const API_KEY = "12345";
export function calculate() { return 100; }
  1. 1. Prefix declarations with the `export` keyword.

  2. 2. Alternatively, use `export default` for primary module values.

  3. 3. Make code public to other importer modules.

02 Practical Example

Here is how you might see this concept applied in real-world code:

practical.js
export default class UserProfile {
  constructor(name) { this.name = name; }
}

Key Takeaway

Use `export` to expose module functionality safely to other parts of your application.

Related Concepts