无论你是次彻 JavaScript 新手还是老手,无论你是底解在面试工作,还是执行只是源码下载做常规的开发工作,通常会发现给定几行代码,机制你需要知道要输出什么以及以什么顺序输出 . 由于 JavaScript 是次彻一种单线程语言,我们可以得出以下结论: let a = 1; console.log(a); let b = 2; console.log(b); 然而,网站模板底解JavaScript 实际上是执行这样的: setTimeout(function(){ console.log(start) }); new Promise(function(resolve){ console.log(start for); for(var i = 0; i < 10000; i++){ i == 99 && resolve(); } }).then(function(){ console.log(start then) }); console.log(end); // Following the idea that JS executes in the order in which the statements appear, I confidently write down the output: // start // start for // start then // end 在 Chrome 上查看它是完全错误的