Facebook Pixel

How do you check if a property is inherited vs own in JavaScript?

Use hasOwnProperty: obj.hasOwnProperty('key') returns true if the property is on the object itself, false if it is inherited from the prototype chain. Or use Object.hasOwn(obj, 'key') in modern JS.

Verify This Answer

Cross-check this information using these trusted sources:

More FAQs in The Prototype Chain: How Property Lookup Works

Check the object itself, then its prototype (__proto__), then the prototype's prototype, up to null. If the property is found, return it. If not found, return undefined.

A method that checks if a property is the object's own (not inherited from the prototype chain). dog.hasOwnProperty('name') is true (own). dog.hasOwnProperty('legs') is false (inherited from animal).

null. Object.prototype is the root of most prototype chains. Object.getPrototypeOf(Object.prototype) returns null. This is how JS knows to stop the lookup.

Still have questions?

Browse all our FAQs or reach out to our support team

Want to upskill yourself?

Our courses are taking a Coffee break, but your curiosity shouldn't. Stay engaged with namastedev linkedin, youtube, discord and other resources while you wait.

0