JavaScript Prototype Chains and Property Lookup
Quick answer
An ordinary object can delegate property reads to another object through its internal prototype link, ending at null.
How it works
Lookup first checks an own property. If absent, it follows the prototype and repeats. A found data property yields its value; a found getter runs with the original receiver. A missing property yields undefined. An own property whose value is undefined still shadows an inherited property. Use Object.getPrototypeOf to inspect the link.
const base = {rate: 4}; const item = Object.create(base);console.log(item.rate, Object.hasOwn(item, "rate"));Expected output in Node.js:
4 falseThe rate is inherited rather than own.
const base = {rate: 4}; const item = Object.create(base);item.rate = undefined; console.log(item.rate, Object.getPrototypeOf(item) === base);Expected output in Node.js:
undefined trueAn own undefined property blocks lookup farther up the chain.
Common mistakes
An object’s internal prototype is not the same thing as a constructor’s public prototype property.
Practice
Draw the prototype chain before and after assigning item.rate.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
JavaScript Prototype Chains and Property Lookup — Knowledge Check
Apply the taught concept and predict the output.
What is checked first in ordinary property lookup?
What ends a prototype chain?
Does an own undefined value allow fallback to an inherited value?
What is the exact console output in JavaScript Prototype Chains and Property Lookup example 1?
const base = {rate: 4}; const item = Object.create(base);console.log(item.rate, Object.hasOwn(item, "rate"));What is the exact console output in JavaScript Prototype Chains and Property Lookup example 2?
const base = {rate: 4}; const item = Object.create(base);item.rate = undefined; console.log(item.rate, Object.getPrototypeOf(item) === base);