Lookup by linked objects
Every JavaScript object has a hidden link to another object called its prototype. When you read a property, the engine checks the object itself, then its prototype, then that object prototype, climbing the prototype chain until it finds the property or reaches null.
- Own properties are found first and shadow inherited ones.
- Methods usually live on the prototype, shared by all instances.
- The chain ends at the base object prototype.
How it is wired
Constructor functions set the prototype through their prototype property, and the new keyword links each instance to it. Modern class syntax is sugar over this same mechanism.
- Object create lets you pick a prototype directly.
- Assigning a property always writes on the object itself, never up the chain.
- A long chain costs a few extra lookups but rarely matters.
Inheritance here is delegation, not copying. Instances stay small and shared behavior lives in one place, which is why prototype methods save memory across many objects.
Key idea
Property reads walk up the prototype chain until found, while writes always land on the object itself.