when we use super() in class ? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 4

when we use super() in class ?

Example code:- class Animal { constructor(name) { this.name = name; } speak() { console.log(this.name + ' makes a noise.'); } } } class Dog extends Animal { speak() { super.speak(); // Super console.log(this.name + ' barks.'); } } let dog = new Dog('Rex'); dog.speak(); // what are the usages of super() ?

12th Jun 2019, 2:04 PM
Injamul Mohammad Mollah
Injamul Mohammad Mollah - avatar
1 Answer
+ 3
The super keyword is used to access and call methods on an object's parent. For example super() would call the parent class contractor() And super.foo() would call the parent class method, foo().
12th Jun 2019, 2:19 PM
Calviղ
Calviղ - avatar