0
Q:

queuemicrotask

setTimeout(() => {
    console.log('hey i am executed asychronously by setTimeout');
},0);

queueMicrotask(() => {
    console.log('hey i am executed asychronously by queueMicrotask');
}); 

output:- 
hey i am executed asychronously by queueMicrotask
hey i am executed asychronously by setTimeout


//reason:- queueMicrotasks are executed after the call stack is empty and before the control is
 send back to the event loop puts the microtask/macrotask of event queue back to the call stack.  
0
queueMicrotask(() => {
  /* code to run in the microtask here */
});
0

New to Communities?

Join the community