← All tutorials

GoCareerGo Tutorials

JavaScript Tutorial

Variables to closures, promises, the DOM and OOP — a complete JS reference.

Inheritance with extends

extends lets one class inherit properties and methods from another, forming a parent-child relationship.

class Animal {
  constructor(name) { this.name = name; }
  speak() { return `${this.name} makes a sound.`; }
}

class Dog extends Animal {
  speak() {
    return `${super.speak()} Specifically, a bark!`;
  }
}

new Dog('Rex').speak();
// 'Rex makes a sound. Specifically, a bark!'
Tip

super() must be called before using 'this' in a subclass constructor — a very common gotcha.