create an object using constructor javascript 1

create an object using constructor javascript

 function Hotel(name, rooms, booked) {
   this.name = name;
   this.rooms = rooms;
   this.booked = booked;
}

 var quayHotel = new Hotel('Quay', 40, 29);
 var parkHotel = new Hotel('Park', 28, 11);

Here is what the above code is Doing:
1. The Hotel() constructor function is defined.
2. The Hotel() constructor function is called with the new operator.
3. The constructor function creates a new object.
4. The constructor function sets the object’s properties.
5. The constructor function returns the new object.

Similar Posts