Assesment help wanted with OOJS 2

Link to the assessment: https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Objects/Test_your_skills:_Object-oriented_JavaScript

Link to my code: https://codepen.io/redorteal/pen/OJamrBZ

In the assessment, I am supposed to implement a Square class inheriting from the Shape class. I have to implement a method called calcArea that will calculate the area of a Square object.

The issue I’m facing:

I declare a property called sideLength in the Square class. I then call the super function with three arguments: {name: 'square', sides: 4, sideLength}.

I expect the superclass to define the sideLength property for the instance. But this.sideLength is undefined when I access it in the calcArea method. If I remove the sideLength declaration from the Square class, sideLength is defined, and everything works as expected.

Why does the sideLength property remain undefined after calling the super function when it is declared in the subclass?

Thanks

Because you’re not initializing it in the subclass. Subclass fields shadow those inherited from the prototype. You need to initialize sideLength in the subclass constructor.