What are modules in JavaScript?

Modules encapsulate code, making it reusable and maintainable. With ES6, JavaScript introduced import and export, allowing modularity and scope isolation.

// math.js
export const add = (a, b) => a + b;
// main.js
import { add } from "./math.js";