$ ./guess_the_languageProblem Solving — fix the bug
Problem Solving — fix the bug · medium · #163

Which fix removes the bug?

const copy = { ...original };
copy.address.city = 'Riyadh';
  1. Clone nested objects too
  2. Freeze the original first
  3. Use Object.assign instead
  4. Declare copy with let
Spread is shallow, so address is still the same object the original references.
Play Problem Solving ▸