In JavaScript, a prototype is a characteristic of an object that enables property delegation. A prototype is a hidden link between two objects, created when an object is instantiated. If an object doesn’t have a property, the lookup is delegated to its prototype.
A series of objects linked via prototypes is called a prototype chain. This chain allows objects to cooperate by sharing behavior and data.
var homework = { topic: "JS" };
homework.toString(); // [object Object]Even though homework doesn’t define toString, it inherits it from Object.prototype via the prototype chain.
var homework = { topic: "JS" };
var otherHomework = Object.create(homework);
otherHomework.topic; // "JS"
otherHomework.topic = "Math";
homework.topic; // "JS"otherHomework is linked to homework, but assigning topic creates a new property on otherHomework, shadowing the original.
Object.create(null) creates a standalone object with no prototype linkage — useful in some cases.
The dynamic nature of this allows prototype-linked methods to behave correctly depending on the calling object. This is crucial for method reuse.
var homework = {
study() {
console.log(`Please study ${this.topic}`);
}
};
var jsHomework = Object.create(homework);
jsHomework.topic = "JS";
jsHomework.study(); // Please study JS
var mathHomework = Object.create(homework);
mathHomework.topic = "Math";
mathHomework.study(); // Please study MathAlthough study is defined on homework, this resolves to the calling object — jsHomework or mathHomework.
Prototypes in JavaScript enable powerful delegation and reuse of behavior. Using Object.create, you can build logical chains of objects. The dynamic behavior of this ensures that delegated methods behave correctly, making prototypes a key feature for object-oriented design in JS.