⊗jsOpBsCC 10 of 60 menu

Constructor in OOP in JavaScript

There is a special method that will be called when a new class object is created. This method is called constructor. Let's implement it in our class:

class User { constructor() { console.log('+++'); } }

Let's now create an object of the class and make sure that the method is called:

new User; // will bring out '+++'

Make a constructor for the Employee class.

byhihyfrde