Skip to main content
D
JavaScript
JavaScript Modules

JavaScript Modules

JavaScript modules split large codebases into smaller files.

Read Time
5 min read
Difficulty
Beginner
Last Updated
Jun 15, 2026
Version
v1.0.0

Introduction

JavaScript files can quickly become too large to read or manage. Developers split the code into smaller, separate files called modules. They then export specific variables or functions from one file and import them into another.

Example

Example
1/* this exports and imports code */
2// inside person.js
3export const name = "Jesse";
4
5// inside main.js
6import { name } from "./person.js";

Key Points

  • The `export` keyword makes code available to other files.
  • The `import` keyword pulls code in from other files.
  • Modules strict mode automatically.
  • HTML script tags require `type="module"` to use them.

Up Next

Continue your journey with the next topic.

Go to JS ES6+ Features