JS ⟩ value ⟩ object ⟩ property ⟩ testing properties
check whether an object has a property.
'prop' in obj // in operator Object.hasOwn(obj, 'prop') // recommended obj.hasOwnProperty('prop') // not recommended obj.propertyIsEnumerable('prop')
⭐ the following methods/operators all support String / Symbol keys.
in
.hasOwn()
.hasOwnProperty()
.propertyIsEnumerable()
Every property in JavaScript objects can be classified by 3 factors:
String / Symbol
enumerable / non-enumerable
own / inherited (from the prototype chain)
📘 MSN
in operator
for-in vs. for-of vs. in
property enumeration
Proxy intercepts property testing.
JavaScript: The Definitive Guide ⟩ 6.5 Testing Properties
Enumerability and ownership of properties ⭐️
Object.prototype ⟩
Object ⟩
.getOwnPropertyNames()
for...in
JavaScript Guide: Inheritance revisited
Last updated 1 year ago