Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial


Eric Kidwell
Eric Kidwell
12,327 Points

Why is it important to learn the different object notations in JavaScript?

Why is it important to learn the different object notations in JavaScript? (Such as literal, dot, constructor, etc)

It seems to me that I'd just want to use literal all the time. Is that wrong? I wonder if there are situations where using the others are beneficial in certain situations, but I can't think of any.

2 Answers

Eric Kidwell
Eric Kidwell
12,327 Points

From what I can tell from my research:

objects created with literal notation are good:

  1. when you are storing/transmitting data between applications
  2. for global or configuration objects that set up information for the page

Objects created with constructors are good when:

  1. you have lots of objects used with similar functionality (ie, multiple slide shows, media players, game characters) within a page
  2. a complex object might not be used in the code
David Smith
David Smith
21,220 Points

the link below are an answer regarding the difference between literal and constructor to create objects