PDA

View Full Version : Javascript super keyword



charlesprabhu
04-11-2023, 06:23 AM
In JavaScript, the super keyword is used to call methods or access properties of a parent class within a subclass.

When a class extends another class, the subclass can call the constructor and methods of the parent class by using the super keyword.

For example, to call the constructor of the parent class, we can use super() inside the constructor of the subclass. This is useful when we want to inherit properties and behavior from the parent class.

The Car class calls the super keyword in its constructor to call the constructor of the parent Vehicle class and set the make and model properties. It then adds its own year property.