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

What is the correct fix?

const users = {};
if (users.hasOwnProperty('toString')) {
  console.log('custom');
}
  1. Use Object.hasOwn(users, 'toString')
  2. Use Object.hasKey(users, 'toString')
  3. Change the test to 'toString' in users
  4. Compare users.toString !== undefined
hasOwnProperty can be shadowed by a key of the same name; Object.hasOwn is safe.
Play Problem Solving ▸