Master JavaScript Promise & Async Execution
Step through the event loop, microtask & macrotask queues, async/await suspension, and tricky async patterns. Detailed MDN-linked explanations reveal after every answer.
Questions
- Not answered. In what order do the values log?
- Not answered. In what order do the values log?
- Not answered. In what order do the values log?
- Not answered. In what order do the values log?
- Not answered. In what order do the values log?
- Not answered. Two timers are registered with the same delay. In what order do the values log?
- Not answered. What is the state of
pat the momentconsole.logreads it? - Not answered. Which of these schedule work on the microtask queue? (Select all that apply.)
- Not answered. Which word is logged first?
- Not answered. When does the event loop process the microtask queue?
- Not answered. In what order do the values log?
- Not answered. A promise is resolved and rejected multiple times. What logs?
- Not answered. What does throwing inside an executor do?
- Not answered. The executor never calls
resolveorreject. What logs? - Not answered. What happens when you construct a promise without an executor:
new Promise()? - Not answered. A promise is resolved with another promise. In what order do the values log?
- Not answered. The resolver is captured and called later. In what order do the values log?
- Not answered.
Promise.resolvereceives a custom thenable. In what order do the values log? - Not answered. In what order do the values log?
- Not answered. The first callback has no
return. What logs? - Not answered.
.thenis called with a non-function argument. What logs? - Not answered. One callback returns a promise. Where does
bland relative to thetchain? - Not answered. Several handlers are attached to the same promise. What logs?
- Not answered. One chain and one fork on the same promise. In what order do the values log?
- Not answered. Two independent chains. In what order do the values log?
- Not answered. In what order do the values log?
- Not answered. What does
finallydo to the value flowing through? - Not answered. Is the promise returned by
.thenthe same object? - Not answered. Which call is
promise.catch(handler)exactly equivalent to? - Not answered. The fulfillment handler throws. Which handler catches it?
- Not answered. What arguments does a
finallycallback receive? - Not answered. The
finallycallback throws. What logs? - Not answered. In what order do the values log?
- Not answered. What happens to the
.thenbetween the rejection and the.catch? - Not answered. The first
.catchre-throws. What logs? - Not answered. Two
.catchlinks in a row. What logs? - Not answered. An async function with no
await. In what order do the values log? - Not answered. In what order do the values log?
- Not answered. Both
awaits receivenull, not a promise. In what order do the values log? - Not answered. Two async functions run "concurrently". What does the final log show?
- Not answered. Nested async calls. In what order do the values log?
- Not answered. When
aawaitsb(), when doesb's body run? - Not answered. What does calling an async function return?
- Not answered. Three async functions return the same value three ways. In what order do the labels log?
- Not answered. What happens when you use
awaitinside a regular (non-async) function? - Not answered. Where is top-level
await(outside any function) allowed? - Not answered. Async IIFEs are passed to
Promise.all. In what order do the values log? - Not answered. In what order do the values log?
- Not answered. The same promise is awaited twice. What logs?
- Not answered. Inside an async function, what number does the expression
await 5evaluate to? - Not answered. The second promise finishes first. What does
Promise.alldeliver? - Not answered. One input rejects immediately. In what order do the values log?
- Not answered.
Promise.allreceives an empty array. What logs? - Not answered. The input mixes plain values and promises. What logs?
- Not answered. A fulfillment at 10ms races a rejection at 30ms. What logs?
- Not answered.
Promise.racereceives an empty array. What logs? - Not answered. The fastest promise rejects. What does
Promise.anydeliver? - Not answered. Every input rejects. What logs?
- Not answered. One of three steps fails under
Promise.allSettled. What logs? - Not answered. Which combinator's returned promise never rejects?
- Not answered. A 50ms operation races a 20ms timeout. What logs?
- Not answered. Which combinators can settle before all of their inputs have settled? (Select all that apply.)
- Not answered. An async function throws. In what order do the values log?
- Not answered. An async function is called without
await. What logs (besides any runtime warning)? - Not answered. Can this
try/catch(or a promise.catch) catch an error thrown in a timer callback? - Not answered.
forEachwith an async callback. In what order do the values log? - Not answered. Errors are thrown, caught, and thrown again along one chain. What logs?
- Not answered. A rejection is "handled" by returning
null. What logs? - Not answered. An error passes through a
try/finallywith nocatch. What logs? - Not answered. When must a rejection handler be attached to avoid an
unhandledrejectionevent? - Not answered. In what order do the values log?
- Not answered. One function throws, the other returns
Promise.reject. What logs? - Not answered.
queueMicrotaskand.thenare mixed. In what order do the values log? - Not answered. Microtasks enqueue more microtasks. In what order do the values log?
- Not answered. Microtasks keep scheduling more microtasks. In what order do the values log?
- Not answered. An async function competes with
queueMicrotask. In what order do the values log? - Not answered. Chained
.thens interleave withqueueMicrotask. What does the final log show? - Not answered. In browsers, what happens to
setTimeout(fn, 0)when timers are deeply nested? - Not answered. Two timers with the identical delay. In what order do they fire?
- Not answered. A timer is cancelled right after scheduling. What logs?
- Not answered. A 10ms timer vs. a 50ms busy-wait. In what order do the values log?
- Not answered. What happens with a gigantic delay:
setTimeout(fn, 2 ** 31)? - Not answered. A microtask schedules a timer while one is already pending. In what order do the values log?
- Not answered. What is the key behavioral difference between
setInterval(fn, 100)and a recursivesetTimeout(fn, 100)? - Not answered. A
for awaitloop over a synchronous-looking async generator. In what order do the values log? - Not answered. The generator awaits a timer between yields. In what order do the values log?
- Not answered.
for awaitover an array of promises with mixed timing. In what order do the values log? - Not answered. What does the
next()method of an async iterator return? - Not answered. Sequential awaiting vs
Promise.all. Which label logs first? - Not answered. In what order do the values log?
- Not answered. A promise-based
sleep. In what order do the values log? - Not answered. Microtask yield vs macrotask yield. In what order do the values log?
- Not answered. A callback API is wrapped in a promise. In what order do the values log?
- Not answered. How many times is
flakycalled in total? - Not answered.
mapwith an async callback. What logs? - Not answered. Both operations are started before the first
await. What logs? - Not answered. After the race is decided, what happens to the slow promise?
- Not answered. An in-flight
fetchis aborted viaAbortController. What happens to its promise? - Not answered. Which statements about async/await are true? (Select all that apply.)
- Not answered. The grand finale — every mechanism at once. In what order do the numbers log?