JavaScript·Intermediate·Coding·1 min read
Are imported values copied?
Short interview answer
No. Imports are read-only views of live exported bindings. If the exporting module updates a binding, importers observe the new value. Importers cannot assign to the imported binding.
Example
// counter.jsexport let count = 0;export const inc = () => { count++; };
// main.jsimport { count, inc } from './counter.js';inc();console.log(count); // 1 — live view, not a snapshotcount = 5; // TypeError — imports are read-onlyKey takeaway
Explain the underlying mental model clearly, then support it with a concrete example and its trade-offs.