In JSLint, it warns that
var x = new Array();
(That's not a real variable name) should be
var result = [];
What is wrong with the 1st syntax? What's the reasoning behind the suggestion?
It's safer to use []
than it is to use new Array()
, because you can actually override the value of Array
in JavaScript:
Array = function() { };
var x = new Array();
// x is now an Object instead of an Array.
In other words, []
is unambiguous.