Advanced JavaScript / Prototypes
Prototypes
When a property isn't found on an object, JavaScript keeps looking — up the prototype chain.
Every object has an internal link to another object called its prototype. When you access a property, JavaScript checks the object itself first; if it's not there, it follows the prototype link and checks that object, and so on, until it reaches `Object.prototype`, whose own prototype is `null` — the end of the chain. This is how every plain object gets access to methods like `toString()` without you ever defining them.
Codeeditable — Run executes your edits
Loading...
Console
Output will appear here
Visualization
Prototype Chain
user
{ name: "Ana" }
__proto__
Object.prototype
toString, hasOwnProperty…
__proto__
null
end of the chain
Why?
toString isn't user's own property, so JavaScript walks the prototype chain: user → Object.prototype, where toString actually lives, then stops there since Object.prototype's own prototype is null.