Consider below code snippet
class Person{
constructor(firstName,age){
this.name = firstName;
this.age = age
}
speak(){
console.log('Hello');
}
}
function ConstructorPerson(firstName,age){
this.name = firstName;
this.age = age
this.speak = function(){
console.log('Hello');
}
}
const personByClass = new Person('Pranjal',23)
const personByConstructorPerson = new ConstructorPerson('Pratik',22)
console.log(personByClass);
console.log(personByConstructorPerson);
→ Person is class and ConstructorPerson is constructor function (class was introduced in js in ES6)
→ personByClass is instance of Person class
→ personByConstructorPerson is instance of ConstructorPerson constructor function
output:

where is speak function of personByClass? Instance personByConstructorPerson has its own speak but it seems personByClass does not have speak(). It has let’s check

now are able to see speak() of personByClass? Did you notice difference between class and constructor function.
→ personByClass has speak() inside prototype where as personByConstructorPerson has speak()outside prototype. So when someone creates new instance of ConstructorPerson new copy of speak() is created for that instance. Now let’s suppose that someone is creating 1000 instances of ConstructorPerson then 1000 copy of speak() is created ( yeah, I know 1000 copy of age and name is created but here we are focusing on difference between class and constructor function, so avoid the common things). Now if someone creates 1000 instance of Person class, then all the instances does not have it’s own speak() function as that speak function is inside prototype. So between 1000 instance of Person there is only one speak function.