Live Bindings and the Cache
What you'll learn: How exported values in ES modules remain synchronized across all imports through the module cache.
The Core Idea
When you export a variable from a module, JavaScript doesn't create copies for each importer—it creates live bindings. This means every import statement that references an exported variable is actually looking at the same binding in the module cache. If the original module updates that variable, all importers see the updated value immediately.
How It Works
Think of the module cache as a bulletin board in a shared office. When a module exports a variable, it's like pinning a piece of paper to that board. Anyone who "imports" that value isn't getting a photocopy—they're getting a window that looks directly at that same pinned paper. If someone updates what's written on the paper, everyone sees the change instantly.
// counter.js
export let count = 0;
export function increment() {
count++;
}
// app.js
import { count, increment } from './counter.js';
console.log(count); // 0
increment();
console.log(count); // 1 ← sees the updated value!
Even though app.js imported count, it sees the new value after calling increment(). Both the import and the export point to the same binding in the cache.
Why This Matters
This behavior is different from older module systems where you might get a snapshot or copy of values. With live bindings, modules can share state dynamically, making patterns like shared counters, configuration objects, or event registries work naturally across your entire application.
Key Takeaway: ES module exports create live bindings stored in the module cache, so all importers always see the current value—updates in the exporting module are instantly visible everywhere.