Which Keyword for Inheritance in JavaScript

Benjamin Jul 11, 2026

In the realm of JavaScript, inheritance is a fundamental concept that allows new objects to be created from existing objects, inheriting their properties and methods. This process is crucial for code reusability and maintaining a clean, organized structure in your JavaScript applications. But what keyword is used to achieve inheritance in JavaScript?

Declaring a variable in JavaScript using the let keyword
Declaring a variable in JavaScript using the let keyword

Before diving into the keyword, let's briefly understand what inheritance is and why it's important. Inheritance in JavaScript enables you to create new objects that reuse, extend, and modify the behavior inherited from other objects. This promotes code reuse, makes your code more efficient, and helps in maintaining a clean and organized structure.

three different types of inferiances are shown on the diagram, and one is labeled
three different types of inferiances are shown on the diagram, and one is labeled

Prototypal Inheritance in JavaScript

JavaScript is a prototype-based language, which means that every object has a prototype, and that prototype can have a prototype of its own, and so on, until an object is reached that has null as its prototype. This chain of prototypes forms the prototype chain of an object.

a white man standing in front of a red sign that says, final keyword
a white man standing in front of a red sign that says, final keyword

The keyword used for inheritance in JavaScript is 'prototype'. However, it's important to note that this is not the only way to achieve inheritance in modern JavaScript. With the introduction of ES6, classes were added to JavaScript, providing a more traditional, object-oriented approach to inheritance.

Using 'prototype' for Inheritance

Inheritance
Inheritance

In JavaScript, you can create a new object that inherits from an existing object by setting the prototype of the new object to the existing object. This is done using the 'prototype' keyword. Here's a simple example:

function Parent() {} Parent.prototype.greet = function() { console.log('Hello from Parent!'); } function Child() {}; Child.prototype = new Parent(); let child = new Child(); child.greet(); // Outputs: Hello from Parent!

Inheritance with 'Object.create()'

types of inheritance πŸ’ͺ
types of inheritance πŸ’ͺ

Another way to achieve inheritance in JavaScript is by using the 'Object.create()' method. This method creates a new object with the specified prototype object and properties. Here's how you can use it for inheritance:

function Parent() {} Parent.prototype.greet = function() { console.log('Hello from Parent!'); } function Child() {}; Child.prototype = Object.create(Parent.prototype); let child = new Child(); child.greet(); // Outputs: Hello from Parent!

Inheritance with ES6 Classes

JavaScript Cheatsheet for Beginners | Learn JS Fast (One-Page Guide)
JavaScript Cheatsheet for Beginners | Learn JS Fast (One-Page Guide)

With the introduction of ES6, JavaScript got a more traditional, object-oriented approach to inheritance with the 'class' keyword. Here's how you can achieve inheritance using ES6 classes:

class Parent { greet() { console.log('Hello from Parent!'); } } class Child extends Parent {} let child = new Child(); child.greet(); // Outputs: Hello from Parent!

What is Inheritance in Java – 5 Types, Use and Advantages
What is Inheritance in Java – 5 Types, Use and Advantages
The JavaScript Cheat Sheet Every Beginner Wishes They Had
The JavaScript Cheat Sheet Every Beginner Wishes They Had
πŸŽ‰πŸ‘¨β€πŸ‘©β€πŸ‘§β€πŸ‘§ JavaScript Visualized: Prototypal Inheritance
πŸŽ‰πŸ‘¨β€πŸ‘©β€πŸ‘§β€πŸ‘§ JavaScript Visualized: Prototypal Inheritance
the different types of children's names and their meanings are shown in this diagram
the different types of children's names and their meanings are shown in this diagram
Types of Inheritance in Programming
Types of Inheritance in Programming
JavaScript Full Notes Every Beginner Must Save πŸ’‘
JavaScript Full Notes Every Beginner Must Save πŸ’‘
10 Example of this keyword in Java
10 Example of this keyword in Java
Inheritance in Java
Inheritance in Java
different types of inerttances are shown on the whiteboard with red and blue lettering
different types of inerttances are shown on the whiteboard with red and blue lettering
Java Final Keyword Cheat Sheet – Explained Simply
Java Final Keyword Cheat Sheet – Explained Simply
JavaScript Objects: The Key to Structured Data πŸš€
JavaScript Objects: The Key to Structured Data πŸš€
Data Types in JavaScript
Data Types in JavaScript
JavaScript Basics You MUST Know
JavaScript Basics You MUST Know
JavaScript Return Values: Get the Most Out of Your Functions πŸš€
JavaScript Return Values: Get the Most Out of Your Functions πŸš€
Type of Inheritance in Python
Type of Inheritance in Python
Data type in Javascript
Data type in Javascript
two screens showing the same number of words in each word, and one with an arrow pointing
two screens showing the same number of words in each word, and one with an arrow pointing
10 JavaScript Concepts Every Beginner Must Know (Save This Cheat Sheet!)
10 JavaScript Concepts Every Beginner Must Know (Save This Cheat Sheet!)
Java List of Keywords (All Reserved Words) | Complete Java Reference Guide
Java List of Keywords (All Reserved Words) | Complete Java Reference Guide
β€˜this’ KeyWord in JavaScript & How it Works
β€˜this’ KeyWord in JavaScript & How it Works

Using 'super' in ES6 Classes

In ES6 classes, you can use the 'super' keyword to call the constructor of the parent class or access a method or property on the parent class. Here's an example:

class Parent { constructor() { console.log('Parent constructor'); } greet() { console.log('Hello from Parent!'); } } class Child extends Parent { constructor() { super(); // Calls the parent constructor console.log('Child constructor'); } greet() { super.greet(); // Calls the parent's greet method console.log('Hello from Child!'); } } let child = new Child(); child.greet(); // Outputs: Parent constructor, Hello from Parent!, Hello from Child!

In conclusion, while the 'prototype' keyword is used for inheritance in traditional JavaScript, modern JavaScript provides a more object-oriented approach with ES6 classes. Understanding and utilizing these concepts effectively can greatly enhance your JavaScript development experience. Happy coding!