π₯ Who wins when we have tasks waiting to be implemented in Job queue as well as in Callback queue.
Hmmmm.... let's see who wins with the piece of code below. π
// setTimeout is a web API which waits for the time as given // in 2nd parameter and then moves the callback function in
// call back queue
setTimeout(() => console.log('1'), 0);
setTimeout(() => console.log('2'), 10);
// Promise is a class in JavaScript so the functionality is
// native, to handle the functions executed we have a Job
// queue
Promise.resolve('hi').then((data) => console.log('3'))
console.log('4');
If you execute this code the logs will be
4
3
1
2
This proves that JobQ has priority over callback queue if call stack is empty, Of course!.
Thoughts in comments
π¦ β¨οΈ
Top comments (0)