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.
More Related Contents:
- What does "use strict" do in JavaScript, and what is the reasoning behind it?
- Why avoid increment (“++”) and decrement (“–“) operators in JavaScript?
- What is the difference between `new Object()` and object literal notation?
- How to initialize an array’s length in JavaScript?
- How to fix jslint error ‘Don’t make functions within a loop.’?
- Immediate function invocation syntax
- (…()) vs. (…)() in javascript closures [duplicate]
- JavaScript function order: why does it matter?
- How to split a long regular expression into multiple lines in JavaScript?
- What is array literal notation in javascript and when should you use it?
- JSLint is suddenly reporting: Use the function form of “use strict”
- Should I use JSLint or JSHint JavaScript validation? [closed]
- Why should you not use Number as a constructor? [duplicate]
- JSlint error ‘Don’t make functions within a loop.’ leads to question about Javascript itself
- JSlint: unexpected ‘for’ [duplicate]
- JSLint error: Move all ‘var’ declarations to the top of the function
- Don’t make functions within a loop [duplicate]
- JSLint “insecure ^” in regular expression
- JSLint Expected ‘===’ and instead saw ‘==’
- Why is JSHINT complaining that this is a strict violation?
- JSLint Error: Unexpected ‘this’
- What does the JSLint error ‘body of a for in should be wrapped in an if statement’ mean?
- JSLint: was used before it was defined
- JSLint: Using a function before it’s defined error
- JSLint: control comments (selective ignore)
- JavaScript open in a new window, not tab
- Expression inside switch case statement
- Overriding Browser’s Keyboard Shortcuts
- Dollar sign before self declaring anonymous function in JavaScript?
- What is ?