let testArray = [1, 2, 3];
or we can use the keyword
new like this:
let testArray = new Array(1, 2, 3);
The two examples above do exactly the same, create new array with values. But what is the difference, which approach we should use and why?
To find out let's test the first snippet here.
After each code execution I refreshed the page
and results varied between
So, let's do the same with second code snippet here.
For some reason, results variations are more common, so I had results from
~1500ms to even
So, the outcome of this simple post is kinda obvious:
For simplicity, readability and execution speed, use the first one (the array literal method).
Thanks for reading!