What is the prototype chain?
Every object in JavaScript has a hidden link to another object, and that other object is called its prototype. When you read a property that the object does not have itself, the runtime looks at the prototype, and if that object does not have it either, it looks at the prototype of that object, and so on until it reaches an object with no prototype at all.
That sequence of objects is the prototype chain, and it is how inheritance works in the language. Nothing is ever copied. An object that inherits from another one does not contain a copy of the parent's properties, it contains a reference to the parent, and every lookup walks down that reference.
const animal = {
speaks: true,
describe: function () { return 'I am an animal'; }
};
const dog = Object.create(animal);
dog.name = 'Rex';
console.log(dog.name); // 'Rex' - own property
console.log(dog.speaks); // true - inherited
console.log(Object.getPrototypeOf(dog) === animal); // trueTwo facts about the chain are worth stating plainly. First, it is a lookup and not a copy, so a change made to the parent is visible through every child that inherits from it. Second, the chain always ends at the object prototype, which has no prototype of its own. That last object holds the methods that every object has, such as toString and hasOwnProperty.
Because the chain is walked every time a property is missing, an object that is missing many properties takes longer to read than an object that has them directly. That is one of the reasons that the engine keeps track of the shape of an object, so that the common case of many objects with the same layout stays fast.