Search code examples
javascript

Should I use bracket notations (`[ … ]`, `{ … }`) or `new Array` and `new Object` to construct arrays and objects?


When initialising Arrays and Objects in JavaScript, is there any difference between these two statements:

var a = [];
var a = new Array();

or between these two statements:

var b = {};
var b = new Object();

If there is a difference, which is to be preferred?


Solution

  • there aren't any significant differences. You could use both, but if you use javascript for web client side scripting, it's better to use the shorter syntax, because the shorter the javascript code, the faster it will get downloaded and executed.