What is Super Function in JavaScript



Use the super() function to call the constructor of the parent class and access functions on an object's parent class.

Example

You can try to run the following code to implement super()

Live Demo

<!DOCTYPE html>
<html>
   <body>
      <script>
         class Department {
            constructor() {}
            static msg() {
               return 'Hello';
            }
         }
         class Employee extends Department {
            constructor() {}
            static displayMsg() {
               return super.msg() + ' World!';
            }
         }
         document.write(Employee.displayMsg());
      </script>
   </body>
</html>
Updated on: 2020-01-08T10:55:23+05:30

239 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements