Promise callbacks
Deferring promise reactions until synchronous work completes.
JS Puzzles · Const
The microtask queue is the internal PromiseJobs queue used for promise handlers. Handlers are queued asynchronously and run in FIFO order after the current synchronous code finishes.
JavaScript stores ready promise handlers in the internal PromiseJobs queue, commonly called the microtask queue. The engine runs queued handlers only after the current synchronous code has finished, taking them in FIFO order; chained handlers are queued and therefore remain asynchronous.
Promise.resolve().then(() => console.log("microtask"));
console.log("synchronous");The synchronous log runs first; the promise handler runs after the current code finishes.
Deferring promise reactions until synchronous work completes.
Understanding the order of chained then, catch, and finally handlers.
Explaining why settled promises still invoke callbacks later.
Promise handlers are placed in the internal PromiseJobs queue, also called the microtask queue. They run only after the current synchronous code has completed.
Follow-up: What ordering does the queue use? It is FIFO, so the earliest enqueued handler runs first.
The queue is first-in-first-out: handlers added first are executed first. A queued handler runs only when the engine is no longer executing other code.
Follow-up: Does an already fulfilled promise make its handler synchronous? No; promise handling always passes through the microtask queue.
Each handler in a chain is queued independently, so every then, catch, or finally callback remains asynchronous. A later handler waits until earlier queued work and the preceding chain step have completed.
Follow-up: Why can a chain appear sequential? Each callback returns a promise whose settlement queues the next handler.
Promisethen()catch()finally()PromiseJobsevent loopawait