Sitemap

JavaScript Prototype —

2 min readOct 7, 2026

Imagine Riya is building a university app. She needs to create hundreds of student objects. Every student should have common abilities like introduce() and study().

Instead of putting the same method inside every student, JavaScript gives them a Prototype.

📖 The Story

1. Riya creates a Student blueprint

function Student(name, age) {
this.name = name;
this.age = age;
}

Now she creates a shared method:

Student.prototype.introduce = function () {
return `Hi, I'm ${this.name} and I'm ${this.age} years old.`;
};

2. Riya creates students

const riya = new Student("Riya", 21);
const john = new Student("John", 22);

Each object has its own data:

riya → name, age
john → name, age

But both can use the same introduce() method from the prototype.

🔗 How JavaScript Finds the Method

When we write:

riya.introduce();

JavaScript searches like this:

riya
│
↓
Does riya have
introduce()? ❌
│
↓
Student.prototype
│
↓
introduce() ✅
│
↓
Execute

This searching process is called the Prototype Chain.

🏫 Easy Real-Life Example

Think of a school:

Students
│
├── Riya
├── John
└── Aman
│
↓
School Rules
├── study()
├── attendClass()
└── followRules()

The students don’t each need their own copy of the school rules. They can share the common rules.

Get Raveenanagar’s stories in your inbox

Join Medium for free to get updates from this writer.

That’s similar to how JavaScript objects use prototypes.

⭐ Why Prototype?

  • Code reuse — common methods can be shared.
  • Memory efficiency — methods don’t need to be copied into every object.
  • Inheritance — objects can access behavior from their prototype.
  • Prototype chain — JavaScript can search through linked prototypes.

🧠 Remember This

Object = student
Prototype = shared blueprint/rules
Prototype chain = the path JavaScript follows to find properties and methods

So, the easiest definition is:

A prototype is an object from which another JavaScript object can inherit properties and methods.

Press enter or click to view image in full size

--

--

Raveenanagar
Raveenanagar

Written by Raveenanagar

Enthusiast Web Developer | JavaScript | HTML | CSS