title: ways to check for empty array in a conditional in JS
body: <p>I'm wondering why my conditional statement where I'm trying to sort out the edge case of the input array being empty doesn't seem to work. With my current test case, the result I get is NaN (no idea why). If I change the conditional to <code>if (array.length === 0)</code>, then my code functions the way I want it to. Isn't <code>[]</code> the correct representation of an empty array though?</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>function getAvg(array) {
    if (array === []) {
      return 0;
    }
    var sum     = 0;
    var average = 0;
    var length  = array.length;
    for (var i  = 0; i &lt; length; i++) {
        sum += array[i];
    }
    average = sum / length;
    return average
  }
  
  var input  = [];
  var result = getAvg(input);
  
  console.log('should be 0:', result);</code></pre>
  </div>
  </div>
  </p>