JS prototype inheritance vs classes

What are JavaScript Classes? JavaScript objects have a hidden internal property called [[Prototype]], which is a reference to another object. What are JavaScript Prototypes? JavaScript objects have a hidden internal property called [[Prototype]], which is a reference to another object. javascript function Person(name) { this.name = name; } Person.prototype.greet = function() { console.log(`Hello, my name is ${this.name}`); }; const john = new Person('John'); john.greet(); // "Hello, my name is John"

Mar 9, 2025 - 09:59
 0
JS prototype inheritance vs classes

What are JavaScript Classes?

JavaScript objects have a hidden internal property called [[Prototype]], which is a reference to another object.

What are JavaScript Prototypes?

JavaScript objects have a hidden internal property called [[Prototype]], which is a reference to another object.


javascript
function Person(name) {
  this.name = name;
}

Person.prototype.greet = function() {
  console.log(`Hello, my name is ${this.name}`);
};

const john = new Person('John');
john.greet(); // "Hello, my name is John"