#Tricky#Event Loop

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.

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 Hoisting, Closures, this binding, Asynchronous operations, and the Event Loop.

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

Frequently asked questions

What are output-prediction questions actually testing?
Whether you can run the code in your head in the right order. Almost every one turns on the event loop — synchronous code first, then the microtask queue drained completely, then one macrotask — or on a coercion rule you either know or guess at. They are quick to ask and very hard to bluff.
Why do so many of them involve setTimeout with a delay of zero?
Because zero does not mean now. The callback cannot run until the call stack is clear, it queues behind every pending microtask, and the specification clamps deeply nested timeouts to roughly four milliseconds. `setTimeout(fn, 0)` means "as soon as reasonably possible", and demonstrating that you know the difference is the whole point of the question.
How should you talk through one in an interview?
Out loud, in execution order, naming the queue each piece lands in. "This logs immediately. This schedules a microtask. This schedules a macrotask." An interviewer learns far more from that narration than from a correct final answer arrived at silently — and if you get it wrong, the reasoning is what they respond to.
What topics come up most?
Promise resolution order, `this` binding in regular versus arrow functions, closures inside loops with `var` and `let`, hoisting and the temporal dead zone, and `==` coercion. Those five cover most of what gets asked.

Related Challenges

Continue learning with these related challenges

View All
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 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.

JavaScript · ES6Pratik Rai ·

JavaScript

Memoize

Cache a function by its arguments so the same call never computes twice.

JavaScript · ES6Pratik Rai ·