New Operator in Javascript | Explained

New Operator in Javascript

In this article, we will see about the new operator in javascript. “new” operator is used to create new objects.

Object:

objects any real-world entity is considered an object. For example, if you are creating a college management system web application, then student, faculty, course, college, university, etc. can be considered an object. An atom, a world, a car, or anything can be considered an object and we can represent any object with the help of a new operator.

Example:

var stud1 = new object();
stud1.rollnum = 1;
stud1.name = "john";

document.write(stud1.rollnum); //1
document.write(stud1.name); //john
  1. In the above code, we have created the object “stud1” using a new operator.
  2. Then we created the “roll num” property for the object “stud1” and assigned the value “1”.
  3. And also created the “name” property for the object “stud1” and assigned the value “john”.
  4. Finally, we printed the properties.

Leave a Reply