How does prototypal inheritance work in JavaScript? How do ES6 classes relate to prototypes?
Show the explanation
Model answer. Every object has a hidden link to another object, its prototype (Object.getPrototypeOf(obj)). When you read a property that the object does not have, JavaScript looks it up on the prototype, then the prototype's prototype, and so on: the prototype chain, ending at Object.prototype and then null.
const animal = { describe() { return `${this.name} makes a sound`; } };
const dog = Object.create(animal); // dog's prototype is animal
dog.name = 'Rex';
dog.describe(); // found on animal via the chainClasses are syntax over the same mechanism. Methods defined in a class body live on ClassName.prototype, shared by all instances; extends links one prototype to another.
class Account {
#balance = 0; // truly private field
deposit(n) { this.#balance += n; return this.#balance; }
}
class Savings extends Account {
constructor(rate) { super(); this.rate = rate; } // super() before using this
}
Object.getPrototypeOf(Savings.prototype) === Account.prototype; // trueClasses add conveniences (super, private #fields, static members, strict mode), but typeof Account is still 'function', and instances still inherit through prototypes.
Original UniCircle question. Last reviewed 22 Oct 2026.
