(function () {
var foo = true
if (foo) {
var bar = foo * 2;
console.log(bar)
}
console.log(msg,'hello-var 声明');
{
var msg;
msg = 'hello-var 声明';
}
{
let msg;
console.log(msg,'hello-let 声明');
msg = 'hello-let 声明';
}
console.log(bar, '3333')
// var声明的变量会导致变量声明提升
})()
var msg;
console.log(msg);
msg = 'hello';
// msg的声明被提升到作用域顶部,即使语句不会执行,声明任然会被提升。
console.log(msg);
console.log(bar, '444')
// 作用域内的声明不会被提升至外部