title: Why use window.onload
body: <p>I have tried finding an answer to this on my own, but only found instructions on how to use onload events. I seem to be missing the point.</p>
  
  <p>I've been taught that if I want something to happen when the page loads, I should use window.onload like this:</p>
  
  <pre><code>&lt;script&gt;
      window.onload = dosomething();
  
      function dosomething()
      {
          window.alert('hello');
      }
  &lt;/script&gt;
  </code></pre>
  
  <p>But now that I am thinking on my own I wonder what the point of doing that is. Because this also produces the same result:</p>
  
  <pre><code>&lt;script&gt;
      dosomething();
  
      function dosomething()
      {
          window.alert('hello');
      }
  &lt;/script&gt;
  </code></pre>
  
  <p>Anything I put at the top inside <code>&lt;script&gt;</code> is going to execute anyway... so what's the point of window.onload?</p>