事件循环 EventLoop

JS事件循环(Event Loop)_藏锋de刃的博客-CSDN博客_js事件循环

setTimeout(function () {
  console.log('three');
}, 0);
 
Promise.resolve().then(function () {
  console.log('two');
});
 
console.log('one');
 
// one
// two
// three
async function async1() {
    console.log("async1 start");
    await async2();
    console.log("async1 end");
  }
  async function async2() {
    console.log("async2");
  }
  console.log("script start");
  setTimeout(() => {
    console.log("setTimeout");
  }, 0);
  async1();
  new Promise((resolve) => {
    console.log("promise1");
    resolve();
  }).then(() => {
    console.log("promise2");
  });
  console.log("script end"); 



script start
async1 start
async2
promise1
script end
async1 end
promise2
setTimeout


版权声明:本文为cctvcqupt原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。