class syntax (ES6) is syntactic sugar over this prototype-based system.
Prototype chain
Every object has an internal[[Prototype]] link (accessible via Object.getPrototypeOf() or __proto__). Property lookups walk the chain until found or null is reached.
Constructor functions
When called with
new, a constructor: (1) creates a new object, (2) sets its [[Prototype]] to Constructor.prototype, (3) binds this to the new object, (4) returns the object automatically.Class syntax (ES6)
Key concepts
| Concept | Description |
|---|---|
prototype | Property on constructor functions; becomes [[Prototype]] of instances |
__proto__ | Accessor to [[Prototype]] of an instance (use Object.getPrototypeOf instead) |
Object.create(proto) | Creates a new object with proto as its prototype |
hasOwnProperty(key) | Returns true if the property is on the object itself, not the prototype |
instanceof | Checks if Constructor.prototype exists in the prototype chain |
Prototype vs own property
Common interview questions
What is the difference between __proto__ and prototype?
What is the difference between __proto__ and prototype?
prototypeis a property on constructor functions (and classes). It is the object that becomes the[[Prototype]]of instances created withnew.__proto__(orObject.getPrototypeOf(obj)) is a property on every object that points to its prototype — the object it inherits from.
How does Object.create differ from new?
How does Object.create differ from new?
Object.create(proto) creates a new object with proto as its prototype, without calling any constructor function. new Constructor() calls the constructor and also sets up the prototype link automatically.What is the difference between classical and prototypal inheritance?
What is the difference between classical and prototypal inheritance?
Classical inheritance (Java, C++) — classes are blueprints; instances are copies of the class. Inheritance happens through class hierarchies at compile time.Prototypal inheritance (JavaScript) — objects inherit directly from other objects. There are no classes at the language level (ES6
class is syntax sugar). Inheritance is dynamic — you can modify prototypes at runtime.