I've stumbled upon something strange.... Maybe someone can try explaining the difference between these two:
var a1=Array(2);
var a2=Array.apply(null,a1);
console.log(a1);
console.log(a2);
console.log(a1[0]===a2[0]);
notice the items are equal but the console log of the arrays looks different (on Chrome and NodeJS).
also other aspects of them seem to work differently:
a1.map(function(i){console.log("!");})
a2.map(function(i){console.log("!");})
notice that map itereares only for a2 not for a1.
this happens on NodeJS, Chrome and FF.
a1=Array(2)setsa1to an array with length 2, but doesn't explictly assign any elements. Whereasa2=Array.apply(null,a1)is like sayinga2=Array(undefined,undefined), i.e., it explicitly sets the value of two elements toundefined..map()only iterates elements that have been explicitly set.someArray[someIndex]will returnundefinedfor two possible reasons: 1. because the element atsomeIndexwas never assigned a value, or 2. because the element atsomeIndexwas explicitly assignedundefined. And youra1[0]===a2[0]test is comparing reason 1undefinedwith reason 2undefined.