使用var 定义变量还会提升变量声明,即
使用var定义:
function hh(){
console.log(a);
var a = 'hello world';
}
hh() //undefined

不使用var定义:
function hh(){
console.log(a);
a = 'hello world';
}
hh() // 'a is not defined'

这就是使用var定义的变量的声明提前。

相关文章: