r/javascript • • Feb 23 '13

Common JavaScript "Gotchas"

https://github.com/stevekwan/best-practices/blob/master/javascript/gotchas.md
16 Upvotes

50 comments sorted by

View all comments

3

u/wkdown Feb 23 '13

Quick question: which is the 'proper' way to instantiate an object?

var obj1 = {};

or

var obj2 = new Object();

Both return [object Object] and typeof "object". Is one better than the other?

3

u/niallpaterson Feb 23 '13

Use the first ({}) because "Object" in "new Object" can be redefined.