$ ./guess_the_languageProblem Solving — fix the bug
Problem Solving — fix the bug · hard · #74

Which fix removes the subtle bug?

const clone = { ...user };
clone.address.city = 'Riyadh';
console.log(user.address.city);
  1. Deep copy: structuredClone(user) first
  2. Deep copy: Object.freeze(user) first
  3. Spread it twice to reach nested values
  4. Assign with clone.address = 'Riyadh'
Spread copies one level, so address is shared and the write leaks into user.
Play Problem Solving ▸