title: array.length returns undefined if the last element is undefined in javascript
body: <p>I have the following code:</p>
  
  <pre><code>function lastElement(array) {
    if (array.length &gt; 0)
      return array[array.length - 1];
    else
      return undefined;
  }
  
  alert(lastElement([ undefined,1, 2]));
  </code></pre>
  
  <p>Which returns 2 since it doesn't counts the undefined element &amp; that's perfectly fine.Now if i swap the last element in the array with the undefined:</p>
  
  <pre><code>function lastElement(array) {
    if (array.length &gt; 0)
      return array[array.length - 1];
    else
      return undefined;
  }
  
  alert(lastElement([ 1, 2,undefined]));
  </code></pre>
  
  <p><strong>It returns undefined!!</strong> Why is it so? Any help appreciated.</p>