title: What is the way of declaring an array in JavaScript?
body: <p>I'm just learning JavaScript and it seems like there are a number of ways to declare arrays.</p>
  
  <ol>
  <li><code>var myArray = new Array()</code></li>
  <li><code>var myArray = new Array(3)</code></li>
  <li><code>var myArray = ["apples", "bananas", "oranges"]</code></li>
  <li><code>var myArray = [3]</code></li>
  </ol>
  
  <p>What are their difference, and what are the preferred ways?</p>
  
  <p>According to <a href="http://www.hunlock.com/blogs/Mastering_Javascript_Arrays" rel="noreferrer">this website</a> the following two lines are very different:</p>
  
  <pre><code>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
  </code></pre>
  
  <blockquote>
    <p>As you can see these two lines do two very different things. If you
    had wanted to add more than one item then badArray would be
    initialized correctly since Javascript would then be smart enough to
    know that you were initializing the array instead of stating how many
    elements you wanted to add.</p>
  </blockquote>
  
  <p>Is what the authors trying to say is <code>Array(10)</code> creates an array with precisely 10 elements and <code>[10]</code> creates an array of undefined size with the 0th element being 10? Or what does this mean?</p>