func1(); //lastfunctionfunc1(){
console.log('This is first func1');
}
func1(); //lastfunctionfunc1(){
console.log('This is last func1');
}
提升后的代码模拟
functionfunc1(){
console.log('This is first func1');
}//该函数被后一个覆盖。functionfunc1(){
console.log('This is last func1');
}
func1(); //最终打印的都是last
func1(); //最终打印的都是last
变量和函数同名
在提升的时候,如果有变量和函数同名,会忽略掉变量,只提升函数
alert(foo); //undefined 函数体functionfoo(){}
var foo = 2;
alert(foo); //2