extends
In JavaScript, the extends keyword makes one class inherit from another, so instances of the new class get the parent’s methods and the class itself gets the parent’s static members. It appears only in the heritage clause of a class declaration or class expression, and the class it creates is called a derived class.
extends links two prototype chains. The derived class’s prototype object inherits from the parent’s .prototype, and the derived class inherits from the parent constructor.
The expression after extends can be any constructor with a .prototype object, including a built-in such as Error or a function call that returns a class, or null. Any other value throws a TypeError. Inside a derived constructor, code must call super() before it reads this. A derived class without a constructor gets a default one that passes all its arguments to the parent.
extends was added in ES2015, together with class syntax.
JavaScript extends Keyword Syntax
The extends clause follows the class name:
class <Name> extends <ParentExpression> {
<classBody>
}
JavaScript extends Keyword Examples
The Square class extends Shape and inherits its methods:
> class Shape {
… describe() {
… return `${this.name} with area ${this.area()}`;
… }
… }
undefined
> class Square extends Shape {
… constructor(side) {
… super();
… this.name = "Square";
… this.side = side;
… }
… area() {
… return this.side ** 2;
… }
… }
undefined
> const tile = new Square(3);
undefined
> tile.describe()
'Square with area 9'
> tile instanceof Shape
true
Square doesn’t define .describe(), so the call finds it on Shape.prototype through the prototype chain, and instanceof reports the instance as a Shape.
The value after extends must be a constructor or null:
> const settings = { theme: "dark" };
undefined
> class Config extends settings {}
Uncaught TypeError: Class extends value #<Object> is not a constructor or null
JavaScript extends Keyword Use Cases
- Sharing methods between related classes through a common parent
- Defining custom error types that inherit from
Error - Specializing a built-in such as
MaporArraywith extra methods - Composing behavior with mixins, functions that return a class extending their argument
Have a question about this? Mentor AI can show you examples, compare related terms, and point you to tutorials.
By Leodanis Pozo Ramos • Updated Nov. 4, 2026