{}内定义的变量是局部变量

function fun(){

    var a = 1;
    console.log(a);

}
fun();

console.log(a);

2023-06-29T09:08:20.png

函数的参数也是局部变量

function fun(a){
    a = 2;
    console.log(a);


}
fun(1);

console.log(a);

2023-06-29T09:19:54.png

函数的作用域

function ww(){
    var a = 1;
    function qq(){
        console.log(2)

    }

}
ww();
qq();

2023-06-29T09:25:38.png

function ww(){
    var a = 1;
    function qq(){
        console.log(2)

    }
qq();

}
ww();

2023-06-29T09:26:31.png