QUESTION: How does class inheritance work?
Class inheritance in modern JavaScript is built on the basis of syntactic sugar over prototypal inheritance and is implemented using the extends keyword. For a child class to successfully inherit from a parent class, a construct of the form class Child extends Parent {} is used. At the same time, creating an instance of a child class requires strict compliance with the rules for working with the constructor. If a descendant class defines its own constructor, calling super() in it is mandatory and must be on the very first line before accessing the this keyword. This is necessary to correctly initialize the context of the parent class. If you omit the super() call, the interpreter will throw an error.
In addition to initialization, the super operator is actively used to call parent methods from the child class. For example, if in the child class you want to extend the functionality of a method that already exists in the parent, you can write super.method() inside your overridden method to first execute the parent's logic and then add your own. Method overriding allows you to flexibly customize object behavior for specific task requirements.
To check whether an object belongs to a specific class or constructor function, the instanceof operator is used. It allows you to safely determine whether an object was created based on a specific class, which is especially useful when working with class hierarchies and polymorphism.