Class Inheritance in JavaScript

From the JavaScript cheat sheet · Classes · verified Jul 2026

Class Inheritance

Extending classes with inheritance

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

class Dog extends Animal {
  constructor(name, breed) {
    super(name); // call parent constructor
    this.breed = breed;
  }
  
  bark() {
    return 'Woof!';
  }
}
💡 super() must be called before using this in constructor
⚡ Use super.method() to call parent methods
📌 Private fields start with # and are truly private
🔥 Static methods are inherited but not instance methods

Continue with JavaScript

Save the full cheat sheet or work through every related task.

More JavaScript tasks

Back to the full JavaScript cheat sheet