浏览器与 Node.js 事件循环的区别
浏览器事件循环
执行同步代码(当前宏任务)→ 清空微任务队列 → UI渲染 → 执行下一个宏任务
console.log("1"); // 同步代码
setTimeout(() => {
console.log("2"); // 宏任务
}, 0);
Promise.resolve().then(() => {
console.log("3"); // 微任务
});
console.log("4"); // 同步代码
// 输出顺序: 1 4 3 2Node.js 事件循环
主要区别
实际应用中的影响
最后更新于