InterviewHubPRO
Section Overview
Q260

Question 260 of 521

Part 5: ES6+ Modern Syntax, Classes, Modules & Destructuring (254 - 328)

50%
JavaScript Internals (521 Qs)•Part 5: ES6+ Modern Syntax, Classes, Modules & Destructuring (254 - 328)

What is a constructor method

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
  class Employee {
    constructor() {
      this.name = "John";
    }
  }

  var employeeObject = new Employee();

  console.log(employeeObject.name); // John