#Tricky#Event Loop

Promise Output Challenges

Challenge yourself with Promise output quiz questions. Test your understanding of async execution order, resolve/reject behavior, microtasks, and the JavaScript event loop.

By Pratik Rai

This collection tests your deep understanding of the JavaScript runtime. You will be presented with snippets of code and asked to predict the console output. These cover topics like Promise executor order, resolve and reject, and the event loop.

Goal: Test your JavaScript knowledge by predicting the correct output for each snippet. Aim for 100% accuracy!

Frequently asked questions

Why do promise-ordering questions come up so often?
Because they compress the whole asynchronous model into five lines. Getting one right means you know that the executor runs synchronously, that `.then` callbacks are microtasks, and that microtasks drain completely before the next macrotask — three facts that explain most real async bugs.
What is the single most common trap?
Assuming the executor is deferred. The function you pass to `new Promise` runs immediately and synchronously; only the callbacks are queued. A `console.log` inside the executor fires before anything after the constructor.
What does chaining actually return?
A new promise each time, which is why the value returned from one `.then` becomes the fulfilment value of the next, and why returning a promise from inside a `.then` waits for it rather than passing it along unwrapped. Most ordering surprises in longer chains come from that unwrapping step.
What else is worth knowing before answering these?
That a settled promise never changes — a `resolve` followed by a `reject` is ignored. That `.catch` is `.then(null, fn)`, so its position in the chain decides what it can catch. And that `async`/`await` is the same machinery, so an `await` is a `.then` for the purpose of working out ordering.

Related Challenges

Continue learning with these related challenges

View All
JavaScript

JS Output Challenges

Test your JavaScript skills by predicting console output for tricky code snippets. Covers hoisting, closures, this binding, async operations, and event loop quiz questions.

JavaScript · ES6Pratik Rai ·

JavaScript

Get smart in javascript

Level up your JavaScript expertise with advanced tips, tricks, and gotchas. Master closures, hoisting, coercion, and event loop behavior to write cleaner, bug-free code.

JavaScript · ES6Pratik Rai ·

JavaScript

Promise Pool

Run a list of async tasks with a hard limit on how many are in flight at once — the concurrency control Promise.all does not give you.

JavaScript · ES6Pratik Rai ·