What is prototypal inheritance, and how does the prototype chain resolve a property?
Every JavaScript object has a hidden link to another object called its prototype. When you read a property, the engine looks on the object itself; if it is not there, it follows the link to the prototype, then to that object's prototype, and so on until it reaches null. That path is the prototype chain, and a missing property simply returns undefined at the end of it.
The pieces that confuse people:
Object.getPrototypeOf(obj)gives you an object's prototype. The legacy__proto__accessor does the same thing.- A function's
.prototypeproperty is not that function's prototype. It is the object that will become the prototype of instances created withnew. classsyntax is sugar over exactly this mechanism.extendssets up the chain; there is no separate class system underneath.
Why it matters practically: methods live on the prototype, so a thousand instances share one copy of each method rather than each carrying its own. It is also why for...in walks inherited enumerable properties and Object.keys does not.





