Know the event loop (sync > microtask > macrotask), hoisting (var=undefined, let/const=TDZ), closures (capture variable not value), this (5 binding rules), and promise chaining (return values). Practice 20+ questions.
JavaScript Interview: Output Prediction Questions
How do I prepare for JavaScript output prediction questions?
The answer
More FAQs in JavaScript Interview: Output Prediction Questions
1, 4, 3, 2. Sync code (1, 4) runs first. Then microtasks (3, Promise.then). Then macrotasks (2, setTimeout). This is the fundamental event loop order.
3, 3, 3. var is function-scoped; all callbacks share one i, which is 3 by the time they run. Use let to fix (logs 0, 1, 2).
1, 3, 2. Code before await runs synchronously (1). await pauses the function and schedules the rest as a microtask. Code after the foo() call runs (3). Then the rest of foo runs (2, microtask).
Still have questions?
Browse all our FAQs or reach out to our support team
Want to upskill yourself?
Your learning library
Small steps. Big possibilities.
Find your next course. Build something great.