Objects are references, not copies
Explain why assigning an object to a new variable does not create an independent copy.
The move: ask what two names point to. Object assignment copies the reference, not the whole structure. This is a useful feature when you intentionally want shared state, but it is a common source of accidental UI bugs, especially with arrays of objects. Primitive values Strings, numbers, booleans, null, undefined, symbols, and bigints are primitives. If let a = 3; let b = a; b = 4, a is still 3. The variable was reassigned. Object references Objects and arrays are reference values. If const b = a and a is an object, both names point to the same object.…
Sign up free — one personalized lesson every day, matched to your role and goals.
Already have an account? Sign in