What happens when a property is not found in the prototype chain?
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.
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
