---
title: "What is the purpose of the \"super\" keyword in JavaScript classes, and how is it used?"  
description: "What is the purpose of the \"super\" keyword in JavaScript classes, and how is it used?"  
author: "Sandra Emily"  
published: 2023-10-08  
updated: 2023-10-09  
canonical: https://www.mindstick.com/forum/160073/what-is-the-purpose-of-the-super-keyword-in-javascript-classes-and-how-is-it-used  
category: "javascript"  
tags: ["javascript", "super", "keywords"]  
reading_time: 2 minutes  

---

# What is the purpose of the "super" keyword in JavaScript classes, and how is it used?

What is the [purpose](https://yourviews.mindstick.com/view/247/no-fail-policy-failing-its-purpose) of the "[super](https://yourviews.mindstick.com/story/4496/5-super-ayurvedic-food-for-bodybuilding)" [keyword](https://www.mindstick.com/forum/33572/sql-inner-join-keyword) in [JavaScript](https://www.mindstick.com/articles/874/how-to-create-watermark-text-for-textbox-by-using-javascript) classes, and how is it used?

## Replies

### Reply by Aryan Kumar

In JavaScript classes, the **super** keyword is used to call functions or methods defined in the parent class (also known as the superclass or base class). Its primary purpose is to access and execute these parent class functions within the context of the current subclass. This allows you to extend the behavior of the parent class in your subclass while still being able to use the functionality provided by the parent.

Here's how you can use the **super** keyword in JavaScript classes:

**Constructor:** In a subclass constructor, you can use **super()** to call the constructor of the parent class. This ensures that the initialization code in the parent class is executed before the subclass's own initialization.

```plaintext
class Parent {
  constructor(name) {
    this.name = name;
  }
}

class Child extends Parent {
  constructor(name, age) {
    super(name); // Call the parent class constructor
    this.age = age;
  }
}

const child = new Child("Alice", 25);
console.log(child.name); // Outputs: "Alice"
console.log(child.age);  // Outputs: 25
```

**Method Calls:** You can use **super.methodName()** to call a method defined in the parent class from the subclass. This allows you to override methods in the parent class while still having access to the original method.

```plaintext
class Parent {
  greet() {
    return "Hello from Parent!";
  }
}

class Child extends Parent {
  greet() {
    return `${super.greet()} And Child!`;
  }
}

const child = new Child();
console.log(child.greet()); // Outputs: "Hello from Parent! And Child!"
```

In summary, the **super** keyword is a crucial tool for working with inheritance in JavaScript classes. It helps maintain the connection between parent and subclass, allowing you to build on and customize the behavior of the parent class as needed.


---

Original Source: https://www.mindstick.com/forum/160073/what-is-the-purpose-of-the-super-keyword-in-javascript-classes-and-how-is-it-used

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
