Prototype
In one line
A prototype is an object that other objects inherit properties and methods from, forming the prototype chain.
In simple words
Every JavaScript object has a prototype — another object that it inherits properties and methods from. When you access a property, JavaScript checks the object first, then its prototype, then the prototype's prototype, and so on up the chain until it finds the property or reaches null.
This is called the prototype chain, and it is how inheritance works in JavaScript. Unlike class-based languages, JavaScript uses prototypal inheritance — objects inherit directly from other objects.
ES6 class syntax is syntactic sugar over prototypes. When you write a method in a class, it is added to the class's prototype object. All instances share the same prototype methods, which is memory-efficient.
Example
const animal = { eat() { return "eating"; } };
const dog = Object.create(animal);
dog.bark = () => "woof";
console.log(dog.eat()); // "eating" — inherited from prototype
console.log(dog.bark()); // "woof" — own propertydog inherits eat from its prototype (animal) and has its own bark method.
Related terms
Related Resources
Related Lessons
- Objects
Learn about prototypes.
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.