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

What is the correct fix?

function clone(obj) {
  const copy = obj;
  copy.x = 99;
  return copy;
}
  1. Change copy.x to obj.x
  2. Use const copy = { ...obj }
  3. Return obj instead
  4. Use Object.keys(obj)
Assigning shares the reference; spread to make a real copy.
Play Problem Solving ▸