JavaScript extends

Beginner
5 min read
Updated: Nov 2026
3 examples

Definition and Usage

class Child extends Parent sets up prototype inheritance. Use super in the constructor and super.method() to call parent methods.

JavaScript Syntax

JavaScript
class Animal {
  speak() { return "…"; }
}
class Dog extends Animal {
  speak() { return "woof"; }
}
console.log(new Dog().speak());
console.log(new Dog() instanceof Animal);
Try it Editor

How It Works

  1. Override. Dog.speak replaces Animal.speak.
  2. instanceof. Dog is still an Animal.

Examples

Example 1 — super.method()

Reuse parent behavior.

JavaScript
class A { hi(){ return "A"; } }
class B extends A { hi(){ return super.hi() + "B"; } }
console.log(new B().hi());
Try it Editor

How It Works

  1. super.hi() calls A.

Example 2 — Prototype chain

Child.prototype → Parent.prototype.

JavaScript
class A {}
class B extends A {}
console.log(Object.getPrototypeOf(B.prototype) === A.prototype);
Try it Editor

How It Works

  1. Links for method lookup.

Example 3 — Extend built-ins carefully

Possible for Error, Array in modern engines.

JavaScript
class E extends Error {}
console.log(new E("x") instanceof Error);
Try it Editor

How It Works

  1. Custom error type.

Frequently Asked Questions

It links the child prototype to the parent prototype and sets Child.[[Prototype]] to Parent.

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

6 people found this page helpful