JavaScript · Junior · Question 62 of 75
How does "toString" in obj differ from Object.hasOwn(obj, "toString") for obj = {}?
- ✓Correct answer:
inistrue(found on the prototype),Object.hasOwnisfalse(not an own property) - 2Both are
false - 3Both are
true
Explanation
in checks the whole prototype chain. Object.hasOwn (a safer replacement for obj.hasOwnProperty) checks only the object itself.