Photo by James Harrison on Unsplash

In this story we will discuss about the concept of prototype in JavaScript and how it helps solving the issues related to OOPs in JavaScript.

But first let’s see what the problem actually is! let’s understand it via below code:

Let’s say we have a constructor function Todo() that is generating us a bunch of todo objects.

function Todo(name,status){
this.name = name;
this.status = status;
this.getTodoName=function(){
console.log(this.name);
}
this.getTodoStatus = function(){
console.log(this.status);
}
}
const todo1 = new Todo("call alex",true);
const todo2 = new Todo("buy medicines",false);
console.log(todo1,todo2);

If you see the output that the program logs you will see that…

Aditya Singh

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store