(function(){
console.log(a)
var a=5;
function a(){}
console.log(a)
function b(){}
b=6
console.log(b)
var c=d=b
})()
为什么a不是因变量提升输出undefined,而是函数?
补充一个:
function fun(ger){
console.log(ger); function ger(){
alert("hello world");
}
}
fun(5)
也是输出了函数 不是变量
提升分两种
变量提升
函数提升
因为你下面声明了一个a函数,当然要打印a函数呀
注意
声明函数有很多种方式,只有 函数声明语句才会提升,即 function a () {}
而其他诸如构造函数,函数赋值等情况声明的函数,则不会提升
像下面这样就只会打印undefined了