JavaScript · Middle · Question 56 of 75
What does this code print?
const a = { user: { name: "Ann" } };
const b = { ...a };
b.user.name = "Bob";
console.log(a.user.name);- ✓Correct answer:
"Bob" - 2
"Ann" - 3
undefined
Explanation
Spread makes a shallow copy: b.user points to the same nested object. Use structuredClone or copy each changed level: { ...a, user: { ...a.user, name: "Bob" } }.