InterviewHubPRO
Section Overview
Q402

Question 402 of 521

Part 6: Async Internals, Memory, Microtasks & Web APIs (329 - 403)

77%
JavaScript Internals (521 Qs)•Part 6: Async Internals, Memory, Microtasks & Web APIs (329 - 403)

What is a microTask queue

Microtask Queue is the new queue where all the tasks initiated by promise objects get processed before the callback queue. The microtasks queue are processed before the next rendering and painting jobs. But if these microtasks are running for a long time then it leads to visual degradation.

Practical Code Example

javascript
// Microtask Queue: Highest-priority queue (Promises, queueMicrotask, MutationObserver)
// The entire microtask queue is drained completely after every JS call stack clearance:
queueMicrotask(() => console.log('1. Microtask executed'));
setTimeout(() => console.log('2. Macrotask executed'), 0);
// '1. Microtask' executes before '2. Macrotask'