JavaScript Literal Objects

Should I ever use object literals and, if so, when should I use them?

Yes, you can use them. Use them when you want to create new objects without explicitly creating a new instance of Object.

Literal objects operate the same as non-literal objects. They just have a more compact syntax. Douglas Crockford recommends using object literals over the Object constructor.


// Not recommended.
let car = new Object();
car.make = "Honda";
car.model = "Prelude";

// Recommended.
let car = {
  make: "Honda",
  model: "Prelude"

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s