There are two ways of creating an object in JavaScript: using the object literal, or using a constructor. The object literal is used when we want to create fixed objects, whereas a constructor is used when we want to create objects dynamically at runtime.
Let's consider a case where we may need to use the constructor instead of the object literal. Here is a code example:
const student = { name: "Eden", printName() { console.log(this.name); } } student.printName(); //Output "Eden"
Here, we created a student object using the object literal, that is, the {} notation. This works well when you just want to create a single student object.
But the problem arises when you want to create multiple student objects. Obviously, you ...