JavaScript Foundations·Build and ship

Modules and tooling

Split code into files, share it with import and export, and run a real project with npm.

Beginner 12 min read Lesson 14 of 480 Challenge included
What you will be able to do
  • Use named and default exports
  • Install and script tools with npm
  • Understand why a bundler helps

A module is a file with its own scope. Exports are the public surface; imports pull values in. Modern tooling installs packages and runs scripts consistently.

math.jsJavaScript
// math.js
export function add(a, b) {
  return a + b;
}

export default function multiply(a, b) {
  return a * b;
}
app.jsJavaScript
// app.js
import multiply, { add } from "./math.js";
console.log(add(2, 3), multiply(2, 3));
terminal.shTerminal
npm init -y
npm install --save-dev vite vitest
npm run dev
npm test
FileJob
package.jsonDependencies and scripts
node_modules/Installed packages (never commit)
vite.config.jsDev server and build settings
.js modulesYour own code, imported by path
Your turn

Split a helper into a module

Medium

Write a format.js module exporting a named formatScore and a default formatName, then import both in app.js.

JAVASCRIPT · starter
// format.js
// write two exports

// app.js
// import both and log a sample
Check your understanding before moving on.
Knowledge checkQuestion 1

Which import reads the named export add from ./math.js?

Select an answer to continue
Study tools

Make it yours.

Keep a private note for this lesson, then turn the key ideas into flashcards you can revisit.

Sign in to save notes and flashcards.Both are private to your account and stay with your progress.
Sign in
Finished reading?

Lock in what you just learned.

Mark this lesson complete to save your place and move one step closer to the certificate.

Next: Testing with Vitest
Lesson 14 of 480 · 0% of course