Prototype Basics in JavaScript

From the JavaScript cheat sheet · Prototypes & Inheritance · verified Jul 2026

Prototype Basics

Understanding the prototype chain

javascript
// Every object has a prototype
const obj = {};
obj.__proto__; // Object.prototype

// Constructor prototype
function Person(name) {
  this.name = name;
}

Person.prototype.greet = function() {
  return `Hello, I'm ${this.name}`;
};

const john = new Person('John');
john.greet(); // method from prototype
💡 Prototype chain: object -> prototype -> prototype -> null
⚡ Methods on prototype are shared, properties usually on instance
📌 Use Object.getPrototypeOf() instead of __proto__
🔥 instanceof checks entire prototype chain

More JavaScript tasks

Back to the full JavaScript cheat sheet