Implementing a Constructor
Learn about the default and other constructors of JavaScript in detail.
We'll cover the following
You know how to create a class, but you haven’t seen how to define the body of the constructor. Creating a class defines a no-parameter default constructor, which appears to be empty bodied. However, you may want to execute some code as part of object construction. For that, you need to define an explicit constructor. That’s exactly what we’ll do next.
Get hands-on with 1400+ tech skills courses.