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".
Is there any difference for javascript variables between with "window.onload" and without it
<!DOCTYPE html>
  <html>
      <head>
      <title>HTML5, CSS3 and JavaScript demo</title>
      </head>
      <body>
      <!-- Start your code here -->
     <script>
     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']); 
   }
  </script>
  <!-- End your code here -->
  </body>
  </html>
 
    