Objects
There is no benefit to using new Object();
-- whereas {};
offers a few.
For defining empty objects they're technically the same. The {}
syntax is shorter, neater (less Java-ish), and allows you to instantly populate the object inline - like so:
var myObject = {
title: 'Frog',
url: '/img/picture.jpg',
width: 300,
height: 200
};
...which usually makes your code more compact, and more readable.
Arrays
For arrays, there's similarly almost no benefit to ever using new Array();
over [];
-- with one minor exception:
var emptyArray = new Array(100);
creates a 100 item long array with all slots containing undefined
-- which may be nice/useful in certain situations.
My recommendation:
- Never use
new Object();
-- it's klunky and looks silly.
- Always use
[];
-- except when you need to quickly create an "empty" array with a predefined length.