setTimeout(() => console.log('1'), 0);
Promise.resolve().then(() => console.log('2'));
console.log('3');
Thanks for reading π
Follow @codedrops.tech for daily posts.
Instagram β Twitter β Facebook
Micro-Learning β Web Development β Javascript β MERN stack β Javascript
codedrops.tech
Top comments (2)
That's going to be
3, 2, 1
. Why:Start execution. Put
setTimeout
's callback into the task queue. Since a promise is already resolved, putthen
's callback into the microtask queue. Executeconsole.log('3');
. Then we execute the microtask(then
's callback) and itsconsole.log(2);
because microtasks are executed before regular tasks whenever the call stack empties. Then the task(setTimeout
's callback) executed andconsole.log(1);
in it.Awesome π₯π