1219基础总结__js变量提升

image.png

变量提升后

function fn(){
    console.log(a,b)
    var a = b = 13
}
var a;var b;

console.log(a,b)  //undefined,undefined
a=12;
b=12;
fn();//函数内私有变量也有提升过程  
     //{var a; b不存在变量提升 ————向上层作用域查找——找到为止}
     //undefined,12
        
console.log(a,b) //12,13

image.png

评论

暂无评论