Why global val is undefined?
the following js don't exec well

index.html

    <script> 
        val1 = 1;
        val2 = 2;
    </script>
    <script src="include.js"></script>

include.js
  
    (function(){
      if(typeof val1 != "undefined"){
         .
         .
      } else {
         //sometime this part
      }
    })();
Why global val is undefined?
===

the following js don't exec well

index.html

    <script> 
        val1 = 1;
        val2 = 2;
    </script>
    <script src="include.js"></script>

include.js
  
    (function(){
      if(typeof val1 != "undefined"){
         .
         .
      } else {
         //sometime this part
      }
    })();