Using parenthesis notation, you can initialize an array with a zero or a large value:
var a= [];
Using new Array() , you can initialize an array with zero or two or more values:
var a= new Array(0);
Referring to multi-parameter syntax, in JavaScript: the final guide , Flanagan writes:
Using an array literal is almost always simpler than using an Array () constructor.
He does not give examples in which a multi-parameter syntax is simpler, and I cannot come up with any. But the words "almost always" imply that there may be such cases.
Can you come up with something?
Please note that I understand the difference between these methods. My question in particular is: why do you need to use multiple parameter syntax with new Array() ? Flanagan suggests that there may be a reason.
source share