原生js作用域(红宝书)

时间:2023-03-08 16:22:38
    function fn(){
var a= b = ;
alert(a); // 2;
}
alert(a);//未被定义;
alert(b);//全局变量;b=2;
        var a = ;
function fn1(){
var a = ;
function fn2(){
alert(a);  // a=5;
}
fn2();
}        
alert(a); // a=1;
fn1(); //这个就是区块域;
给定一个实例:function fn1(){
var a = ;
function fn2(){
function fn3(){
alert(a);
a = ;
}
fn3();
}
fn2();
       alert(a);
}
fn1();
运行程序是这么运行的:function fn1(){
function fn2(){
function fn3(){
alert(a); //这里a = 5;
a = ;
}
fn3();
}
var a = ;
fn2();
      alert(a); //这里a = 10;
}
fn1();
alert(a);