JS变量作用域实例

<script> 
    var scope='hello'; 
    function a(){ 
       console.log(scope);   //undefined 
       var scope='world'; 
       console.log(scope);   //world 
       console.log(b);       //undefined 
       for(var i=0;i<4;i++){ 
               var b=i;      
               console.log(b);    //0 1 2 3 
       } 
       console.log(b);       //3 
    } 
    a(); 
</script> 

 

你可能感兴趣的:(作用域)