Skip to content
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

JavaScript
// 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-only

Key takeaway

Explain the underlying mental model clearly, then support it with a concrete example and its trade-offs.

← Back to JavaScript modules

Related questions