Skip to content

Latest commit

 

History

History
26 lines (19 loc) · 1.69 KB

File metadata and controls

26 lines (19 loc) · 1.69 KB

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