JS Coding Questions Logo
JS Coding Questions
#256💼 Interview💻 Code

What is a constructor method

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); // John

Advertisement

Responsive Ad
🎯 Practice NowRelated Challenge

JavaScript Coding Exercise 85

Test your knowledge with this interactive coding challenge.

Start Coding

Advertisement

728x90
256of476