js是单线程的(非阻塞的),实现方法就是事件循环;
分同步任务和异步任务;
new Promise((resolve,reject) => { resolve(1) console.log('log1') }).then(() => { console.log('log2') }) console.log('log3') setTimeout(() => { console.log('log4') Promise.resolve(2).then(() => { console.log('log5') }) }, 0) setTimeout(() => { console.log('log6') }, 0) console.log('log7')
执行顺序如下:
宏任务--微任务--异步宏任务(对应该供任务的为任务)---下一个异步宏任务
故打印顺序为:
log1 log3 log7 log2 log4 log5 log6
标签:异步,顺序,console,log,js,任务,resolve From: https://www.cnblogs.com/xhliang/p/17321763.html