Advertisement
728x90
The constructor method is a special method for creating and initializing an object created within a class. If you do not specify a constructor method, a default constructor is used. The example usage of constructor would be as below,
javascript
1class Employee {
2 constructor() {
3 this.name = "John";
4 }
5 }
6
7var employeeObject = new Employee();
8
9console.log(employeeObject.name); // JohnAdvertisement
Responsive Ad
🎯 Practice NowRelated Challenge
JavaScript Coding Exercise 85
Test your knowledge with this interactive coding challenge.
Start CodingAdvertisement
728x90
256of476