To create a class inheritance, use the extends keyword.A class created with a class inheritance inherits all the methods from another class.

The extends keyword indicates that you are making a new class that derives from an existing class. The meaning of “extends” is to increase the functionality.


class Child extends Parent{ }


class Car {
 constructor(brand) {
this.carname = brand;
 present() {
return’I have a ‘ + this.carname;

class Model extends Car {
constructor(brand, mod) {
this.model = mod;
 show() {
return this.present() + ‘, it is a ‘ + this.model;

let myCar = new Model(“Ford”, “Mustang”);
document.getElementById(“demo”).innerHTML= myCar.show();

The super() method refers to the parent class.

By calling the super() method in the constructor method, we call the parent’s constructor method and gets access to the parent’s properties and methods.

Inheritance is useful for code reusability: reuse properties and methods of an existing class when you create a new class.

JavaScript Class Inheritance

#JavaScript #Inharitance #OOPS #extends #Probyto #Probyto AI

Subscribe and follow us for latest news in Data Science and Machine learning and stay updated!

Facebook: https://facebook.com/probyto
Twitter: https://twitter.com/probyto
LinkedIn: https://linkedin.com/company/probyto
Instagram: https://instagram.com/probyto