Created
December 27, 2013 02:30
-
-
Save lyuehh/8141741 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var a = 1; // 全局变量 | |
function b(){ | |
a = 2; // 没有var, 就是全局, a变成2了 | |
console.log(a); // 输出2 | |
a = 3; // a变成3了 | |
setTimeout(function(){ //只要是setTimeout, 它就会异步执行, 就算延迟0秒也会异步, 所以这里不会执行了 | |
console.log(a); | |
}, 0); | |
a = 4; // 修改a为4 | |
} | |
b(); // 调用b(), 会先输出第4行的2 | |
console.log(0); // 然后输出这里的0 | |
// 然后就是b方法里的 第7行, 输出4 | |
// 所以答案就是 2 0 4 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment