Skip to content

Files

Latest commit

 

History

History

137-overriding-constructor

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

Overriding constructor easy #javascript

by Pawan Kumar @jsartisan

Take the Challenge

Consider the following code:

class Person {
  constructor(name) {
    this.name = name;
  }
}

class Student extends Person {
  constructor(name, studentId) {
    this.name = name;
    this.studentId = studentId;
  }
}

// Doesn't work!
let student = new Student("Pawan Kumar", 1); // Error: this is not defined.

Why there is an error when creating object of student class? How to fix it?


Back Share your Solutions Check out Solutions