InterviewHubPRO
Section Overview
Q262

Question 262 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)

How do you call the constructor of a parent class

You can use the super keyword to call the constructor of a parent class. Remember that super() must be called before using this reference. Otherwise it will cause a reference error. Let's the usage of it,

javascript
  class Square extends Rectangle {
    constructor(length) {
      super(length, length);
      this.name = "Square";
    }

    get area() {
      return this.width * this.height;
    }

    set area(value) {
      this.area = value;
    }
  }