What is it?
In JavaScript, the object data type is used to store key-value collections and complex data structures. It can be thought as an entity having state and behavior, which are implemented as properties and methods.
Defining objects
To create an object, one can create it using the object literal, using the let
or const
keyword, or with an object constructor.
Using the Object literal
We can create objects using the { } literal. This is a fast way to create any object, but not as flexible as other options.
Creating instances of Object
Using the Object
keyword, one can create a object directly. This is not a so fast way of declaring objects.
Using a object constructor
Using a object constructor is a more concise way of creating objects, once it can be applied to multiple different instances without too much repeated code.
However, one would be better using a class constructor, which would serve the same purpose, but more flexible.