ES6 Modules

ES6 introduced native modules to JavaScript to support modular coding.

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

// main.js
import { add } from './utils.js';
console.log(add(2, 3));

Use export to expose functionality and import to bring it into other files.

← PrevNext →