Solution Review: "super" Keyword
Explore the use of the super keyword in JavaScript object-oriented programming. Understand why calling super in child class constructors is necessary to properly initialize this. This lesson reviews common errors and fixes through practical code examples and explanations for junior to mid-level interview preparation.
We'll cover the following...
Question 1: Solution review
In the previous lesson, you were given the following code:
For the code above, you had to answer the following question:
Explanation
Let’s incorporate each option in our code and see if it’s correct.
Option A: name and sex should be passed as parameters to Human().
Let’s do that and see the result.
The error is still there, so this is not the issue. This makes sense since we are setting definite values for name and sex, so we don’t need to pass the parameters.
Option B: age should be passed as a parameter to the constructor. ...