current position:Home>Promise resolve execution order?

Promise resolve execution order?

2022-08-06 13:14:40segmentfault

The following pieces of code are intercepted from Ruan Yifeng's ES6 tutorial. Why is throw after resolve and log before resolve?How is this order determined?


Other Answer 1:

The function (excutor) in the new promise will be executed synchronously
First resolve(1) and then put the console(r) in then into the microtask queue. At this time, r is the parameter 1 of resolve
and thenExecute print 2

Synchronous task is executed
Execute micro task print 1

Other Answers 2:

copyright notice
author[segmentfault],Please bring the original link to reprint, thank you.

Random recommended