What's the difference between Array(1) and new Array(1) in JavaScript? -


i started thinking this, couldn't differences expose whilst mucking around in jsfiddle.

var = new array(1),     b = array(1);  console.log(a, b); 

output 2 arrays 1 undefined member.

doing for ( in ) reveals have same properties.

what differences between these? first 1 instantiate object explicitly?

please don't lecture me using array literal notation know that. i'm more wishing fill gap in knowledge explained above.

with array, both equivalent. new injected when it's called function:

15.4.1 array constructor called function

when array called function rather constructor, creates , initialises new array object. function call array(…) equivalent object creation expression new array(…) same arguments.

from ecma-262, 3th edition (with similar in 5th edition).


Comments