title: a variable in the function on window.onload is not set properly
body: <p>When I coded like below, variable 'name' does not have a initial value "test".
  This is working fine when I do not use "window.onload".</p>
  
  <p>Is there any difference for javascript variables between with "window.onload" and without it </p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
    &lt;html&gt;
        &lt;head&gt;
        &lt;title&gt;HTML5, CSS3 and JavaScript demo&lt;/title&gt;
        &lt;/head&gt;
        &lt;body&gt;
        &lt;!-- Start your code here --&gt;
  
       &lt;script&gt;
  
       window.onload=function(){ 
       var name = "test";
  
       function foo(msg,msg2) {
  
                console.log(msg + '  ' + msg2);
  
                alert(this.name);
  
    }
  
    foo('normal call','default');
  
    var obj = {
                name : 'steve'
            }
  
    foo.call(obj,'call function','object'); 
    foo.apply(obj,['apply function','object']); 
  
     }
  
  
    &lt;/script&gt;
    &lt;!-- End your code here --&gt;
    &lt;/body&gt;
    &lt;/html&gt;
  </code></pre>