你不知道的js第四章--提升

a = 2;
var a; 
console.log( a );///2

因为var会产生提升声明

console.log( a ); 
var a = 2;

undefine,原因同上

foo(); // 3
function foo() { console.log( 1 );
}
var foo = function() { console.log( 2 );
};
function foo() { console.log( 3 );
}

函数声明优先

foo(); // "b"
var a = true; if (a) {
function foo() { console.log("a"); } }
else {
function foo() { console.log("b"); }
}

尽可能避免在块内部声明函数。

猜你喜欢

转载自blog.csdn.net/qq_36971710/article/details/88287977