JavaScript Class constructor() Method
Example
Example
A class named "tutorialpro" is created and initialized:
Definition and Usage
The constructor() method is a special method (constructor) used to create and initialize objects created within a class.
The constructor method constructor() is automatically called when an object is created.
If no constructor method is explicitly specified, a default constructor method is added.
If a constructor method is not specified, a default constructor method is used.
Within a constructor method, the super keyword can be used to call a parent class's constructor method.
Syntax
constructor(parameters)
Technical Details
| JavaScript Version: | ECMAScript 2015 (ES6) |
Browser Support
constructor() is an ECMAScript6 (ES6) feature.
ES6 (JavaScript 2015) is supported by all major browsers.
| Chrome | Edge | Firefox | Safari | Opera |
| Yes | Yes | Yes | Yes | Yes |
Internet Explorer 11 or older versions of IE do not support the constructor() method.