title: is Javascript array.push method synchronous?
body: <p>I am writing a simple javascript function but it is not as I have expected.</p>
  
  <p>The following is the code: </p>
  
  <pre><code>    var startDate = new Date('2015-07-01 00:00 +0800');
      var endDate = new Date('2015-07-10 00:00 +0800');
      var arrayOfDates = [];
  
      if (endDate &gt;= startDate) {
          while (startDate &lt; endDate) {
              arrayOfDates.push(startDate);
              startDate = new Date(startDate.setDate(startDate.getDate() + 1));
          }
      }
  </code></pre>
  
  <p>While I am expecting the result of <code>arrayOfDates</code> to be <code>[2015-07-01, 2015-07-02, 2015-07-03.... , 2015-07-10']</code>. The results is instead <code>[2015-07-02, 2015-07-03.... , 2015-07-10']</code></p>
  
  <p>Why is that? Is it somehow the <code>var startDate</code> is updated before the variable is pushed to the array? if that's the case how can I make sure the code is running synchronously?</p>