2

I'm learning JavaScript and I'm unclear on the different syntax used to define objects. What is the difference (if any) between defining an object like this:

var myObject = {}

and like this:

var myObject = new Object();

In the admittedly fairly straightforward examples I've worked on I can't yet see a difference in behaviour between the two. It seems to be possible to access and manipulate both objects in the same ways. However, I see both examples used so I assume there is some difference between the two.

Willl
  • 223
  • 4
  • 14
  • 2
    From [ECMAScript 5, 11.1.5](http://www.ecma-international.org/ecma-262/5.1/#sec-11.1.5): *The production... `{ }` is evaluated as follows: Return a new object created as if by the expression `new Object()`...* – apsillers Dec 29 '14 at 14:56
  • Thanks for pointing me towards the dupe question on this. Didn't show up when I posted for some reason. – Willl Dec 29 '14 at 14:59
  • Just saying: this question is clearer, cleaner and more generic than its duplicate. – gideon Dec 29 '14 at 14:59
  • @gideon I'd tend to agree; this question is very well-written. I think it's easier to clean up that question than to try to divert the moment from that question here, though. (I'll take a pass at cleaning up that question now.) – apsillers Dec 29 '14 at 15:03
  • @apsillers I put that in there because I really don't want this question being deleted. It serves as an excellent [sign-post](http://blog.stackoverflow.com/2010/11/dr-strangedupe-or-how-i-learned-to-stop-worrying-and-love-duplication/). Also the title is excellent and methinks will show up easier on googling. – gideon Dec 29 '14 at 15:36

0 Answers0