Skip to content
IT glossary
FrontendUpdated December 3, 2026

Prototypal inheritance

Прототипное наследование

In JavaScript, an object can use properties and methods from another object called its prototype. If the object does not have a requested property of its own, JavaScript looks for it up the prototype chain.

Also known as: prototype, прототип

Delegation, not copying

An array can call map even though the array itself usually has no property named map. JavaScript finds the method on Array.prototype. Other arrays can use that same function. This is prototypal inheritance: objects share behavior by linking to another object rather than copying its properties.

How property lookup works

When you read obj.key, JavaScript checks obj for its own property named key. If it finds none, it checks the object's prototype, then that prototype's prototype, and so on. The first match wins. If the chain ends at null without a match, the read returns undefined.

An own property can hide an inherited property with the same name. This is called shadowing. Even an own property whose value is undefined stops the search. Use Object.hasOwn(obj, 'key') to check whether the object itself has the property, or 'key' in obj to check the object and its prototype chain.

Example: one method, two objects

const account = {
  balance: 0,
  summary() { return `Balance: ${this.balance}`; },
};
const savings = Object.create(account);
savings.balance = 100;

savings.summary(); // 'Balance: 100'
account.summary(); // 'Balance: 0'

Object.create(account) links the new object to account. When you call savings.summary(), JavaScript finds the function on account, but this is savings: where the method is found and which object it is called on are two separate questions. The assignment to savings.balance creates an own property because the inherited balance is a writable data property. Do not generalize this to all assignments: an inherited setter, for example, is called instead.

Where it shows up in practice

Prototype chains explain built-in methods such as Array.prototype.map and inherited methods on browser DOM objects. JavaScript classes use the same mechanism: ordinary public instance methods declared in a class body live on the class's prototype object, and extends links the subclass prototype to the superclass prototype. Instance fields, by contrast, belong to individual instances.

What interviewers ask

Be ready to distinguish Constructor.prototype from Object.getPrototypeOf(instance). The former is a property of the constructor; the latter tells you which object an instance actually links to. For a normal new Constructor() call, the constructor's current .prototype object becomes the new instance's prototype. Replacing that property later does not relink existing instances. A common follow-up is to predict what happens if you delete an own property: the next read can find a property of the same name further up the chain.