These are some of the way to create arrays in js:
- var myArray = new Array()
- var myArray = new Array(3)
- var myArray = ["apples", "bananas", "oranges"]
- var myArray = [3]
What is the difference among them and what is the preferred way?
I read somewhere that the following declarations are completely different
var badArray = new Array(10); // creates an empty Array that's sized for 10 elements
var goodArray= [10]; // creates an Array with 10 as the first element
Is what the authors are attempting to express that [10] generates an array of undefined size with 10 as the 0th element and [10] makes an array of exactly 10 elements? What else does this mean?