The Two Different 'prototype' Concepts
What you'll learn: Why the word "prototype" in JavaScript refers to two completely different things that often confuse beginners.
The Confusion Explained
JavaScript unfortunately uses the word "prototype" for two distinct concepts, which creates massive confusion. Let's separate them clearly:
Concept 1: The prototype property (only on functions)
Every function has a .prototype property that is a plain object. When you use that function as a constructor with new, JavaScript sets the newly created object's internal prototype link to point to this .prototype object.
Concept 2: The [[Prototype]] internal slot (on all objects)
Every object has an internal link called [[Prototype]] (accessed via Object.getPrototypeOf() or __proto__) that points to another object. This creates the prototype chain you've been learning about.
The Relationship
Here's where they connect:
function Dog(name) {
this.name = name;
}
Dog.prototype.bark = function() {
return "Woof!";
};
const myDog = new Dog("Buddy");
// Dog.prototype is a PROPERTY on the constructor function
console.log(Dog.prototype); // { bark: [Function] }
// myDog's [[Prototype]] POINTS TO Dog.prototype
console.log(Object.getPrototypeOf(myDog) === Dog.prototype); // true
Think of it like this: Dog.prototype is a blueprint stored on the constructor function. When new Dog() runs, JavaScript wires up the new object's internal [[Prototype]] link to point at that blueprint.
Remember
When you see .prototype, you're accessing a property. When you use Object.getPrototypeOf(), you're reading an object's internal prototype link. Same word, two different things!
Key Takeaway: The prototype property is a regular property on constructor functions, while [[Prototype]] is an internal link on every object that creates the prototype chain. They work together but are not the same thing.