Do you know what will be the output of this code?
JavaScript
const a = { n: 1, inner: { m: 1 } };
const b = { ...a };
b.n = 2;
b.inner.m = 2;
console.log(a.n, a.inner.m);
Show answer and explanation
The answer is 1 2.
Spread copies top-level properties. n is copied by value, but inner is copied by reference, so both objects share it. Use structuredClone(a) for a deep copy.