JavaScript · Prototype · Junior · Concept
What is the prototype chain, and how does property lookup work?
Short Interview Answer
Objects link to a prototype via `[[Prototype]]`; missing properties are looked up on that chain until found or `null`.
Detailed Explanation
Almost every object has an internal `[[Prototype]]` (accessible via `Object.getPrototypeOf` / `__proto__`). When you read `obj.prop`, the engine looks on `obj`, then its prototype, and so on. Writing `obj.prop =` usually sets an own property (unless a setter exists on the chain). `Object.create(proto)` makes an object with a chosen prototype. `null` prototype objects (`Object.create(null)`) are useful as pure dictionaries without inherited Object methods. Understanding the chain explains inheritance before ES6 classes (which are mostly sugar over prototypes).
Example
const animal = { eats: true };
const rabbit = Object.create(animal);
rabbit.jumps = true;
console.log(rabbit.eats); // true — found on prototypeInterview Tip
Distinguish own vs inherited properties (`hasOwnProperty` / `Object.hasOwn`).
Common Mistake
Confusing `obj.prototype` (on functions) with `Object.getPrototypeOf(obj)`.