title: Why does window.scrollTo() require setTimeout() in order to work?
body: <p>Here's an HTML page that displays three square divs in the upper left corner:</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>window.addEventListener('load', function () {
    console.log('load event has fired')
    window.scrollTo(500, 0);
    // setTimeout(function() { window.scrollTo(500, 0); }, 0);
  })</code></pre>
  <pre class="snippet-code-css lang-css prettyprint-override"><code>body { height: 100vh }
  .bigwidth {
    width: 2000px;
    display: block;
  }
  .square {
    width: 100px;
    height: 100px;
    display: block;
    position: absolute;
  }
  .greenish {
    background-color: #75af99;
  }
  .redish {
    background-color: #ff9b98;
  }
  .bluish {
    background-color: #aabbff;
  }
  .whiteish {
    background-color: #eaeaea;
  }
  * {
    padding: 0;
    margin: 0;
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;div class="whiteish bigwidth" style="height:100%;"&gt;
      &lt;div class="square greenish" style="left:50px; top:50px;"&gt;&lt;/div&gt;
      &lt;div class="square redish" style="left:70px; top:70px;"&gt;&lt;/div&gt;
      &lt;div class="square bluish" style="left:90px; top:90px;"&gt;&lt;/div&gt;
  &lt;/div&gt;</code></pre>
  </div>
  </div>
  </p>
  <p>Right now the <code>window.scrollTo(500, 0);</code> command that occurs on page load has no effect (tested in safari and Chrome). But if we replace it instead by the line</p>
  <pre><code>setTimeout(function() { window.scrollTo(500, 0); }, 0);
  </code></pre>
  <p>(commented out in the above code), the scroll does happen. Why is this?</p>