Facebook Pixel
The Prototype Chain: How Property Lookup Works

What is hasOwnProperty in JavaScript?

The answer

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).

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.

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.

JavaScript returns undefined. It does not throw an error. The lookup traverses the entire chain (obj -> proto -> proto.proto -> ... -> null) and if the property is not found anywhere, returns undefined.

Still have questions?

Browse all our FAQs or reach out to our support team

Want to upskill yourself?

Your learning library

Small steps. Big possibilities.

Find your next course. Build something great.

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

Success

Please Login.

Success

Please Login.

Success

Please Login.

Success

Please Login.

Success

Please Login.

Success

Please Login.

Success

Please Login.

Success

Please Login.

Success

Please Login.

Success

Please Login.

Success

Please Login.

Success

Please Login.

Success

Please Login.

Success

Please Login.

Success

Please Login.

Success

Please Login.

Success

Please Login.

Success

Please Login.

Success

Please Login.

Success

Please Login.