关于函数声明和函数表达式?都能提升?
来源:16-11 作用域和闭包--解题-代码演示
慕粉2232079852
2017-08-22
// 函数声明
f1();//全局作用域下函数声明整体提升了,故没问题,调用f1(),console.log('函数声明')
function f1() {
console.log('函数声明');
}
// 函数表达式
f2();// 按照课程所讲,f2此时提升的是一个变量的声明,按道理f2此时应该是undefined,undefined 再执行()固然会报错,但是在google浏览器下测试是OK,可以console.log('函数表达式')的。
var f2 = function() {
console.log('函数表达式');
}
写回答
1回答
-
我用chrome试着是不行的,会提示“fn2 is not a function”
022017-08-23
相似问题