变量提升

(function(){
     var a = b = 3
};
console.log(a)
)();
console.log(typeof a!=='undefined');
console.log(typeof b!=='undefined');

变量赋值 是从右至左进行赋值  所以 var a = b = 3 等同于 b = 3,var a = b  在给b进行赋值的时候 因为未声明b 所以b提升为全局变量  而a则拥有作用域

你可能感兴趣的:(变量提升)