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.
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.
<!-- 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}!`);
}
Module scripts are automatically deferred and run in strict mode — no need to add defer or "use strict".
More in JavaScript