We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
exercise - 声明提升
The text was updated successfully, but these errors were encountered:
先看变量的:
console.log(a); if (false) { var a = 1; } console.log(a); // 结果: undefined undefined
再看
console.log(a); if (true) { // 这里为 true 了 var a = 1; } console.log(a); // 结果: undefined 1 // true,当然执行了
函数的:
console.log(fn); if (false) { function fn() {}; } console.log(fn); // 结果: undefined undefined
console.log(fn); if (true) { // 这里为 true 了 function fn() {}; } console.log(fn); // 结果: undefined ƒ fn() {} // true,当然执行了
但是这种情况下函数只是声明的提升,函数体并没有提升。
练习练习
console.log(fn); // 执行结果是? function fn() { console.log("fn"); } if (true) { function fn () { console.log("fn1"); } } else { function fn() { console.log("fn2"); } }
init(); function fn() { console.log("fn"); } function init() { fn(); // 执行结果是? if (false) { function fn() { console.log("fn2"); } } }
Sorry, something went wrong.
No branches or pull requests
exercise - 声明提升
The text was updated successfully, but these errors were encountered: