Named export
Exports a specific value by name.
export makes values available from a module. import brings those exported values into another module.
// format.js
export function formatTitle(value) { return value.trim(); }
// app.js
import { formatTitle } from "./format.js";
Modules & Code Organization
Named exports let a module expose multiple specific values. Import statements then select the names they need.
The exported name is part of the module contract. Renaming or removing it can break importing files.
A good module exports a small public surface and keeps implementation details private inside the file.
Exports a specific value by name.
Imports specific exported names.
Renames an import locally with as.
The public names other files rely on.
Examples
const internalCache = new Map();
export function getItem(id) {
return internalCache.get(id);
}
export const cache = new Map();
export let retryCount = 0;
export function temporaryDebugHelper() {}
Code patterns
These examples focus on imports, exports, module boundaries, on-demand loading and file structure you can use in real projects.
Expose one reusable helper.
export function formatTitle(value) {
return value.trim();
}
Use curly braces for named exports.
import { formatTitle } from "./format.js";
Export values after they are declared.
function parseItem(value) { return value; }
function formatItem(value) { return String(value); }
export { parseItem, formatItem };
Avoid local naming conflicts.
import { formatTitle as formatHeading } from "./format.js";
Rules that matter
A module system only helps when files have clear jobs, small public APIs and predictable import paths.
They make imports searchable and explicit.
Do not export values only because they exist.
Aliases help conflicts but can hide the original contract.
A module should have a clear theme.
Two files importing each other can create initialization bugs.
Changing them can break other files.
Production thinking
Import and export create the boundaries that keep a codebase understandable.
Shared accessibility helpers can be exported once and reused consistently.
Production modules should expose stable names and hide implementation details.
Clear module boundaries reduce JavaScript breakage that can affect rendered content.
Live code lab
The preview runs inside an isolated iframe. The JavaScript is placed inside the HTML editor for now, so every example stays together and remains easy to understand.
Mini assignment
Practice assignment
Try it yourself
Self-check
If you can explain what a file exports, what it imports and why it exists, the module structure is doing its job.
Senior audit upgrade
Use these references when browser support, syntax details or proposal status matters.