What are JavaScript modules (import/export)?
Answer
JavaScript modules (ES6) allow splitting code into reusable files. Named exports: export multiple items by name — export const PI = 3.14; export function add(a, b) { return a + b; }. Import: import { PI, add } from "./math.js". Rename: import { add as sum } from "./math.js". Import all: import * as math from "./math.js". Default export: one default per module — export default function() { } or export default class { }. Import: import myFunction from "./utils.js" (any name). Re-export: export { something } from "./module.js". Modules are: always in strict mode, executed once (cached after first import), have their own scope (no global scope pollution), and use static analysis (imports are resolved at compile time, not runtime). Dynamic import: const module = await import("./module.js") — lazy loading.
Previous
What is the difference between synchronous and asynchronous JavaScript?
Next
What is the prototype in JavaScript?