Let’s use the classic example of the parent class “vehicle” and the subclasses “car” and “bike”. The vehicle’s constructor might have code to initialize the frame of the vehicle, count the wheels, and add brakes. The car’s constructor would add an engine and a horn, and call super() (the parent, vehicle’s constructor) to make sure it got a frame and counted the wheels, and have brakes. The bike constructor would add a bell, and pedals, but also call super() to get the frame and count the wheels, and add brakes. Answer from chrissilich on reddit.com
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Operators › super
super - JavaScript | MDN
The super keyword is used to access properties on an object literal or class's [[Prototype]], or invoke a superclass's constructor.
🌐
W3Schools
w3schools.com › jsref › jsref_class_super.asp
JavaScript Class super keyword
The super keyword is used to call the constructor of its parent class to access the parent's properties and methods. Tip: To understand the "inheritance" concept (parent and child classes) better, read our JavaScript Classes Tutorial.
🌐
Educative
educative.io › answers › what-is-the-super-keyword-in-javascript
What is the super keyword in JavaScript?
This is where super comes into play. The super keyword in JavaScript acts as a reference variable to the parent class.
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › javascript-super-keyword
JavaScript Super Keyword - GeeksforGeeks
June 19, 2024 - The super keyword is used to call the parent class's constructor to access its properties and methods. ... This keyword can accepts all the arguments that has been used to create a constructor.
🌐
TutorialsPoint
tutorialspoint.com › super-keyword-in-javascript
Super keyword in JavaScript?
<!DOCTYPE html> <html> <head> <meta charset ="UTF-8"> <meta http-equiv ="X-UA-Compatible" content ="IE=edge"> <meta name ="viewport" content ="width=device-width, initial-scale =1.0"> <title>Super keyword in Javascript</title> </head> <body> <p id="super" style="text-align : center"></p> <script> class Person{ constructor(person_name) { this.name = person_name; } getPersonName() { return this.name; } } class Aadhar extends Person { constructor(person_name,AadharID){ super(person_name); this.AadharID = AadharID; } showAadharId() { return 'The Aadhar ID for the person '+ this.getPersonName() +' is : '+this.AadharID; } } var person_id = new Aadhar('Rajesh','5000 0000 0000 0000'); document.write(person_id.showAadharId()); </script> </body> </html>
🌐
CSS-Tricks
css-tricks.com › what-is-super-in-javascript
What is super() in JavaScript? | CSS-Tricks
November 6, 2019 - That means trout’s this context includes the properties and methods defined in the fish class, plus whatever properties and methods trout defines for itself. Calling super() essentially lets JavaScript know what a fish is so that it can create a this context for trout that includes everything from fish, plus everything we’re about to define for trout.
🌐
Reddit
reddit.com › r/javascript › what does `super()` actually do?
r/javascript on Reddit: What does `super()` actually do?
March 18, 2018 -

I've used it plenty of times, and I've read that it calls the constructor function of its parent class, but I'm not really grasping the concept of it to be honest. I know it's not a concept unique to JS, so if anyone has any good links/examples to explain it in other languages, that would also be great. I thought I understood it, but as I'm trying to learn more about OOP i seem to get more confused by the day lol.

Thanks

🌐
CodeSweetly
codesweetly.com › super-keyword-in-javascript
super Keyword in JavaScript – What Is the super Keyword? | CodeSweetly
The super keyword searches a parent class or object literal for a specified static or prototypal property. ... The super() function call in the snippet above tells the computer to find a constructor in the parent class’s prototype chain.
Find elsewhere
🌐
freeCodeCamp
freecodecamp.org › news › javascript-class-handbook
The JavaScript Class Handbook – Complete Guide to Class Fields and the Super Keyword
May 20, 2024 - We used the super keyword in the snippet above to access the parent class’s static class field. Note: super cannot access a parent class’s instance class field because JavaScript sets an instance property on the object instance, not the class itself or its prototype chain.
🌐
Medium
frontendinterviewquestions.medium.com › super-keyword-in-javascript-10f9b144999e
Super keyword in JavaScript. For more questions and answers visit… | by Pravin M | Medium
September 12, 2024 - The super keyword in JavaScript is a crucial feature in object-oriented programming, particularly when dealing with inheritance. It provides a way to call functions or access properties from a parent class within a subclass.
🌐
YouTube
youtube.com › bro code
The JavaScript SUPER keyword is super! 🦸‍♂️ - YouTube
00:00:00 intro00:00:22 setup00:02:39 super constructor00:05:59 super methods00:09:03 conclusion// super = keyword is used in classes to call the constructor ...
Published   November 19, 2023
Views   14K
🌐
Flavio Copes
flaviocopes.com › javascript-super
The JavaScript super keyword
June 25, 2020 - will now execute 2 console logs. First the one defined in the Car class constructor, the second the one defined in the Tesla class constructor: ... Note that super() can only be called in the constructor, not in other methods.
🌐
Yousaf Khan
yousaf.hashnode.dev › super-in-javascript-an-in-depth-guide
"super" in Javascript
December 4, 2021 - When super() is called inside the constructor of a sub-class, super keyword uses the prototype of the sub-class' constructor to access the super-class constructor and calls it.
🌐
Medium
medium.com › beginners-guide-to-mobile-web-development › super-and-extends-in-javascript-es6-understanding-the-tough-parts-6120372d3420
“Super” and “Extends” In JavaScript ES6 - Understanding The Tough Parts | by Anurag Majumdar | Beginner's Guide to Mobile Web Development | Medium
June 3, 2025 - In line numbers 35 and 39, super is used as an “object” which refers to an Animal instance (parent class). The super keyword here is used to call the methods of the parent class Animal explicitly. People familiar with languages like C#, Java, Python can pretty much relate to how all this works. However, JavaScript was not so simple before ES6 came in, especially for classes.
Top answer
1 of 2
7

If you use this, the engine will first try to access the property on the instance itself. If it doesn't exist on the instance, it'll then go to the prototype (Footballer.prototype). If it doesn't exist there, it'll then go to Human.prototype to see if the property exists.

If you use super, it'll immediately go to the parent class, Human.prototype, to see if the property exists, and will go upward from there (rather than go through the instance and child prototype first).

This will be especially important to keep in mind if a method with the same name exists both on the parent and child, which isn't uncommon.

class Human {
  mouse () {
    console.log('parent class');
  }
}

class Footballer extends Human {
  mouse() {
    console.log('child class');
  }
  talk () {
    super.mouse();
    this.mouse();
  }
}

const f = new Footballer();
f.talk();
2 of 2
0

There is a big difference. In languages like Java and Javascript, with super you are accessing the parent's properties and methods.

With this you are accessing the child's properties and methods.

this.mouse() works because first the mouse property is accessed for the child (Footballer) and when not found the property is looked for in the parent (Human). This is how inheritance works. When accessing a property called x, Javascript will try to move upwards in the prototype chain until it finds a property named x.

If you define a property like kick only in Footballer, then super.kick() will not work but this.kick() will, demonstrating the difference.

class Human {
  constructor (name, age) {
    this.name = name;
    this.age = age;
  }
  mouse (sentense) {
    console.log(`${this.name}: "${sentense}".`);
  }
}

class Footballer extends Human {
  constructor(name, age, position, team) {
    super(name, age);
    this.team = team;
    this.position = position;
  }
  kick(){
  console.log("kicked");
  }
  play(){
    this.kick();
    super.kick();
  }
  talk (sentense) {
    super.mouse(sentense); // This works.
    this.mouse(sentense); // This also works.
  }
}

const messi = new Footballer();
messi.play();
🌐
Medium
medium.com › technology-software › what-is-super-keyword-in-javascript-javascript-interview-questions-16-127a19de824b
What is super keyword in Javascript: Javascript Interview Questions #16 | by Melih Yumak | TechnologySoftware | Medium
February 16, 2023 - Class inheritance enables us to use the parent class functionalities. But how can we change these values and functions while we are creating a new inherited class? Super keyword is used for changing the parent classes defined methods and properties.
Top answer
1 of 2
56

In ES6, derived classes have to call super() if they have a constructor. In react, all components extend from the Component class.

You don't actually need a constructor for every ES6/react class. If no custom constructor is defined, it will use the default constructor. For base classes, it is:

constructor() {}

And for derived classes, the default constructor is:

constructor(...args) {
  super(...args);
}

You also need to call super() before accessing this, since this is not initialized until super() is called.

There are a few reasons to use a custom constructor in react. One is that you can set the initial state within the constructor using this.state = ... instead of using the getInitialState lifecycle method.

You can also bind class methods inside the constructor with this.someClassMethod = this.someClassMethod.bind(this). It's actually better to bind methods in the constructor since they will only be created once. Otherwise if you call bind or use arrow functions to bind methods anywhere outside the constructor (like in the render method), it will actually end up creating a new instance of the function on every render. Read more about that here.

If you want to use this.props in the constructor, you need to call super with props as an argument:

constructor(props) {
  super(props);
  this.state = {count: props.initialCount};
}

If you don't, then this.props is undefined in the constructor. However, you can still access this.props anywhere else in the class outside the constructor without needing to do anything with it in the constructor.

2 of 2
28

The super keyword in JavaScript is used in order to call the methods of the parent class. By itself, super() is used within a constructor function to call the parent constructor function. For example:

class Animal {
  
  constructor(age) {
    console.log('Animal being made');
    this.age = age;
  }
  
  returnAge() {
    return this.age;
  }
  
}

class Dog extends Animal {

  constructor (age){
    super(age);
  }
  
  logAgeDog () {
    console.log(`This dog is: ${ super.returnAge()} years old`);
  }
  
}

const dog = new Dog(5);


console.log(dog);

dog.logAgeDog();

In this example we have a Dog class which extends an Animal class. The Dog class uses the super keyword twice. The first occurence is in the constructor, when super() is used in the constructor it will call the parent class constructor. Therefore we have to give the age property as an argument to it. Now the Dog successfully has an age property.

We can also use super outside of the constructor in order to access the parent's 'class' (i.e. prototype) properties and methods. We use this in the logAgeDog function located in the Dog class. We use the following code:

super.returnAge();

You should read this as:

Animal.returnAge();     // superClass.returnAge()

Why do I need this in React?

You need the super() keyword in React only when implementing a constructor. You have to do the following:

constructor(props) {
  super(props);
  // Don't call this.setState() here!
}

the parent class which is named Component needs to do some initialization on its own in order for React to work fine. If you implement a constructor without a super(props) call this.props in Component will be undefined which can lead to bugs.