I ran this code and got the below result. I curious to know why []
is faster?
console.time('using[]')
for(var i=0; i<200000; i++){var arr = []};
console.timeEnd('using[]')
console.time('using new')
for(var i=0; i<200000; i++){var arr = new Array};
console.timeEnd('using new')
- using
[]
: 299ms - using
new
: 363ms
Thanks to Raynos here is a benchmark of this code and some more possible way to define a variable.