老生常谈之宏任务,微任务

const promise = new Promise((resolve, reject) => {
    console.log(1);
    resolve('22222');
    console.log(2);
    setTimeout(() => {
      console.log(7)
    })
  }).then((res)=>{
    console.log('1111')
    console.log(res)
  });

  promise.then(() => {
    console.log(3);
    setTimeout(() => {
      console.log(6);
    })
  })
  setTimeout(() => {
    console.log(5);
  })
  console.log(4);
VM300:2 1
VM300:4 2
VM300:22 4
VM300:9 1111
VM300:10 22222
VM300:14 3
undefined
VM300:6 7
VM300:20 5
VM300:16 6

老生常谈之宏任务,微任务

相关推荐