title: How to declare Hash.new(0) with 0 default value for counting objects in JavaScript?
body: <p>I'm trying to iterate through an array of digits and count how many times each digit is found in the array.</p>
  
  <p>In ruby it's easy, I just declare a <code>Hash.new(0)</code> and that hash is already been set up for counting from 0 as a value. For example:</p>
  
  <pre class="lang-rb prettyprint-override"><code>arr = [1,0,0,0,1,0,0,1]
  counter = Hash.new(0)
  arr.each { |num| counter[num] += 1 } # which gives {1=&gt; 3, 0=&gt; 5}
  </code></pre>
  
  <p>I wanted to do the same thing in JavaScript but <code>let counter = {}</code> gives me <code>{ '0': NaN, '1': NaN }</code>.</p>
  
  <p>Do you have any idea how to create that same Hash as an Object in JavaScript?</p>