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
- In the above code, we have created the object “stud1” using a new operator.
- Then we created the “roll num” property for the object “stud1” and assigned the value “1”.
- And also created the “name” property for the object “stud1” and assigned the value “john”.
- Finally, we printed the properties.