default export
One primary exported value.
Default imports and namespace imports are two different ways to consume module exports.
import createApp from "./create-app.js";
import * as format from "./format.js";
format.title("Dashboard");
Modules & Code Organization
A default export represents the main value of a module. The importing file chooses the local name.
A namespace import collects all named exports into one object-like namespace.
Both patterns are useful, but overusing them can make code less explicit than named imports.
One primary exported value.
The importing file chooses the local name.
Collects named exports under one namespace.
Named imports usually reveal exactly what a file uses.
Examples
import * as format from "./format.js"; heading.textContent = format.title(record.title);
import * as utils from "./utils.js"; utils.doThing(); utils.otherThing(); utils.unknownThing();
Code patterns
These examples focus on imports, exports, module boundaries, on-demand loading and file structure you can use in real projects.
Common for one main function or class.
export default function createApp(root) {
return { root };
}
No curly braces.
import createApp from "./create-app.js";
Access exports through a namespace.
import * as format from "./format.js";
format.title("Dashboard");
Often clearer for small sets.
import { title, count } from "./format.js";
Rules that matter
A module system only helps when files have clear jobs, small public APIs and predictable import paths.
The module should clearly have a primary export.
They keep dependencies explicit.
format.title reads better than a vague utils bag.
They hide what code really depends on.
Different local names can confuse a team.
A module should have an export style that matches its purpose.
Production thinking
Choosing import style affects how quickly another developer understands a file.
A cohesive namespace can group reusable focus, label or status helpers clearly.
Production codebases benefit from predictable export conventions.
Readable organization reduces the chance of client-rendering failures.
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.