JavaScript Prototypes and Prototypal Inheritance
Understand JavaScript's prototype-based inheritance model.

Prototype Chain#
Code
function Person(name) {
this.name = name;
}
Person.prototype.greet = function() {
return `Hello, I'm ${this.name}`;
};
const person = new Person('John');
person.greet(); // "Hello, I'm John"
// Prototype chain: person -> Person.prototype -> Object.prototype -> nullInheritance#
Code
function Student(name, school) {
Person.call(this, name);
this.school = school;
}
Student.prototype = Object.create(Person.prototype);
Student.prototype.constructor = Student;
Student.prototype.study = function() {
return `Studying at ${this.school}`;
};