JavaScript › ES Modules
What does 'live binding' mean for ES Module exports, and how does it differ from CommonJS?
AdvancedAnswer
ES Module imports are live, read-only views onto the exporting module's variable — if the exporting module later reassigns the exported variable, every importer sees the updated value automatically. CommonJS exports are copied values at the time of require(), so later changes aren't reflected.
// counter.js
export let count = 0;
export function increment() { count++; }
// main.js
import { count, increment } from './counter.js';
increment();
console.log(count); // 1 — reflects the live updateReal-world example Sharing a mutable, always-current configuration value across multiple modules without a getter function.