可能重复:
console.log 对象处于当前状态
我了解基本的同步和异步行为:
// this block gets executed all at once the next time the js engine can run it
setTimeout(function() {
var snacks = "cookies";
snacks += "and popcorn";
console.log("goodbye world");
}, 0);
console.log("hello world"); // this block runs before the block above
我不明白为什么这里的第一个控制台报告[]:
var x = [];
x.push({ a: "c" });
console.log(x); // says []
x.splice(0, 1);
console.log(x); // says []