foo(); var a = true; if (a) { function foo() { console.log(1); } } else { function foo() { console.log(2); } }
在Chrome53和Firefox49中,均没有把foo函数提升,均提示not a function。但是在10.12的Safari10中却被提升并输出2。
在MDN中其实写了这段话
1 2 3 4 5 6
if (shouldDefineZero) { function zero() { // DANGER: compatibility risk console.log("This is zero."); } } ES2015 says that if shouldDefineZero is false, then zero should never be defined, since the block never executes. However, it's a new part of the standard. Historically, this was left unspecified, and some browsers would define zero whether the block executed or not.