ES6 modules are the preferred way of doing modules in JavaScript. They're (now) built into the language and are supported in modern browsers and Node.js. That said, there are still some gotchas to be aware of... which we'll cover.
The syntax for ES6 modules is drop-dead simple. You can export stuff from a module using the export keyword, and import stuff using the import keyword. Let's look at our math example again:
// math.js
export const add = (a, b) => a + b;
export const subtract = (a, b) => a - b;
// main.js
import { add, subtract } from "./math.js";
console.log(add(1, 2)); // 3
console.log(subtract(1, 2)); // -1