SyntaxStudy
Sign Up
JavaScript Introduction to ES Modules
JavaScript Intermediate 4 min read

Introduction to ES Modules

ES Modules

ES modules let you split JavaScript into separate files with explicit imports and exports. Each module has its own scope — no global variable pollution.

Use type="module" on the script tag to enable module syntax in browsers.

Example
<!-- index.html -->
<script type="module" src="main.js"></script>

// main.js
import { greet } from "./utils.js";
greet("Alice");

// utils.js
export function greet(name) {
  console.log(`Hello, ${name}!`);
}
Pro Tip

Module scripts are automatically deferred and run in strict mode — no need to add defer or "use strict".