puzzle 05 · javascript
What does this log?
const a = { nested: { n: 1 } };
const b = { ...a };
b.nested.n = 2;
console.log(a.nested.n);1
2
undefined
TypeError
why
Spread is a shallow copy — b.nested and a.nested point at the same object. Use structuredClone(a) for a deep copy.