How to Create an Empty Object in JavaScript

Here are two primary ways to create an empty Object in JavaScript.

  1. Using Object Literal syntax ({ })
  2. Using Object Constructor (new Object())

Method 1: Using the Object Literal syntax ({ })

The {} syntax is shorter and neater, allowing you to populate the object inline instantly.

let obj = {};




Method 2: Using Object Constructor

The Object constructor can be used with a parameter, and its behavior varies based on the type of the provided value. When you use a new Object() with no arguments, it creates an empty object. However, when you pass a value to the Object constructor, it tries to create a wrapper object for that value.

For example:

  1. new Object(123) returns an object wrapping the number 123.
  2. new Object(“hello”) returns an object wrapping the string “hello”.
let new_obj = new Object();




Both methods will create an empty object, but the object literal syntax ({}) is more concise and is generally preferred.

That’s all!

Related posts

How to Check If an Object is Empty

Display an Object

JavaScript Object Length