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

Export Lists and Re-exporting

Learn to use export lists at the bottom of files and re-export values from other modules.

Export Lists and Re-exporting

You'll learn how to organize exports at the end of a file and funnel exports from other modules through your own.

What Are Export Lists?

Instead of exporting each item at its declaration, you can collect all exports in one place at the bottom of your file using an export list. This is just a cleaner syntax:

// myModule.js
const API_KEY = 'secret123';
function fetchData() { /* ... */ }
class User { /* ... */ }

// Export list at the end
export { API_KEY, fetchData, User };

This is functionally identical to exporting at each declaration, but keeps all exports visible in one spot—great for maintainability.

Re-exporting from Other Modules

Re-exporting means importing something from one module and immediately exporting it from your current module. This creates "barrel" files that aggregate exports:

// utils/index.js
export { fetchData, API_KEY } from './api.js';
export { formatDate } from './formatters.js';
export { User, Admin } from './users.js';

Now other files can import everything from one place:

import { fetchData, formatDate, User } from './utils/index.js';

You can also re-export everything with *:

export * from './api.js';

Analogy: Think of a store that sells products from multiple suppliers. Instead of customers visiting each supplier directly, they visit your store—you're re-exporting the suppliers' goods under one roof.

Key Takeaway: Export lists organize exports at the bottom of files for clarity, while re-exporting lets you create aggregation modules that simplify import paths for consumers.