DEV Community

Cover image for Constructors in JavaScript
Sosanya Esther
Sosanya Esther

Posted on

Constructors in JavaScript

A constructor enables you to provide any custom initialization that must be done before any other methods can be called on an instantiated object.
The Javascript Set constructor is used to create Set objects. It will create a set of unique values of any type, whether primitive values or object preferences.
There are two types of constructors: built-in constructors such as Array and Object, which are available automatically in the execution environment at runtime; and custom constructors, which define properties and methods for your own type of object.

A constructor is useful when you want to create multiple similar objects with the same properties and methods. It’s a convention to capitalize the name of constructors to distinguish them from regular functions.

Top comments (0)