Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

JS Puzzles · Const

Prototype Chain

JavaScript resolves missing properties by walking an object's prototype chain. The chain ends at null; if no object provides the property, the result is undefined.

How it works

Each object can link to another object as its prototype. When a property is missing on the object itself, JavaScript searches that prototype, then continues through successive prototypes until it finds the property or reaches null; a missing property evaluates to undefined.

Syntax

Object.getPrototypeOf(obj)

Parameters

NameTypeDescription
objobjectThe object whose prototype is returned.

Returns

The prototype object associated with the supplied object.

Key points

  • Property access checks own properties first and then searches the prototype.
  • Lookup continues through every successive prototype until a match or the chain's end.
  • A property absent from the entire chain evaluates to undefined.
  • Use Object.getPrototypeOf to inspect a prototype instead of treating __proto__ as the standard API.
  • Object.prototype is the terminal ordinary-object prototype because its prototype is null.
  • Object.create establishes a chosen prototype when creating an object.

Common mistakes

  • A prototype can have its own prototype, creating a chain rather than a single fallback object.
  • Prototype lookup eventually stops at null; it does not continue indefinitely.
  • Do not confuse an object's prototype link with the prototype property found on constructor functions.

Example: Property lookup through a prototype chain

const parent = { greet() { return "hello"; } };
const child = Object.create(parent);

console.log(child.greet());
console.log(Object.getPrototypeOf(child) === parent);

The child has no own greet method, so JavaScript finds it on parent through the prototype chain.

When to use it

Method delegation

Share methods among related objects without copying each method onto every instance.

Prototype inspection

Inspect an object's inheritance relationship during debugging or metaprogramming.

Custom object composition

Create an object that delegates property lookup to a selected parent object.

Interview questions

QHow does property lookup use the prototype chain?

JavaScript first checks whether the object has the requested property. If it does not, lookup continues on the object's prototype, then on that prototype's prototype, until the property is found or the chain ends; an unsuccessful lookup produces undefined.

Follow-up: What terminates the search? The chain terminates at an object whose prototype is null.

QHow can you inspect and create prototype relationships?

Object.getPrototypeOf(obj) returns the object's prototype. Object.create(proto) creates a new object whose prototype is the supplied object, allowing property lookup to delegate to it.

Follow-up: How can the relationship be inspected without relying on __proto__? Use Object.getPrototypeOf, the standard access method described by the documentation.

QWhere does the ordinary object prototype chain end?

Object.prototype is the default prototype for ordinary object literals, and its own prototype is null. Consequently, methods such as toString can be inherited through Object.prototype.

Follow-up: Why does an array also find object methods? Its prototype chain eventually reaches Object.prototype, where those methods are available.

  • Object.getPrototypeOf()
  • Object.create()
  • Object.prototype
  • __proto__
  • property lookup
  • prototypal inheritance

Source: Object prototypes. Checked 2026-10-15.