console.log(f);
f()
if (false/true) {
function f() {
console.log(1);
};
}
//undefined
Uncaught TypeError: f is not a function
if中的f函数的声明会被提前,但是定义不会被提前;(chrome/firefox/IE11)
'use strict';
console.log(f);
if (false/true) {
function f() {
console.log(1);
};
}
//Uncaught ReferenceError: f is not defined
严格模式下会报错(chrome/firefox/IE11);
IE10严格模式会报"在 strict 模式下,函数声明无法嵌套在语句或块内。这些声明仅出现在顶级或直接出现在函数体内。",而非严格可以访问到f函数
IE9及以下不管是不是严格模式都可以访问到f函数;推荐使用表达式函数,在IE/chrome/firefox表现都一样
***for和if表现一样;