Possible Duplicate:
new MyObject(); vs new MyObject;
In some articles I seen following statement to create new object in JavaScript:
var myObject = new Object;
and at some sites:
var myObject = new Object();
In there is any difference between two statements or one is just shorthand?
There’s no difference. Parentheses are optional when using a function as a constructor (i.e. with the
newoperator) and no parameters. When not using thenewoperator, parentheses are always required when calling a function.As noted in another answer, it’s generally preferable to use an object literal instead. It has the following advantages over using the
Objectconstructor:var foo = { bar: "cheese" };)Objectfunction being overwritten.