Appearance
setTimeout(() => { console.log(1) }, 0) new Promise((resolve) => { console.log(2) resolve() }).then(() => { console.log(3) }).then(() => { console.log(4) }) console.log(5)
2 5 3 4 1
注意!!这里的执行顺序是2、5,而不是5、2
因为Promise内部的同步任务加入主线程立即执行,而Promise.then中的任务进入微队列
Promise
Promise.then