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