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

Which fix removes the bug?

const map = {};
map[{ id: 1 }] = 'a';
console.log(Object.keys(map));
  1. Use a Map for object keys
  2. Stringify before indexing
  3. Freeze the key object
  4. Declare map with let
Object keys are coerced to strings, so every object collapses to '[object Object]'.
Play Problem Solving ▸