Creating an object literal
This lesson teaches the different ways to create object literals in JavaScript.
Introduction
Just like other variables in JavaScript, an object too has to be defined and initialized in order to be created. There are various ways to create an object literal.
An object literal can be created:
-
by using figure brackets
{...}
in the declaration. -
by using the
new
keyword. -
based on an existing object by using the
create()
method.
All of these approaches do exactly the same thing.
Syntax
Figure Brackets
An object contains data values and functions known as its properties. Let’s take a look at the syntax for creating an object literal using {..}
:
Get hands-on with 1400+ tech skills courses.