How do I prepare for JavaScript output prediction questions?
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.
Verify This Answer
Cross-check this information using these trusted sources:
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
