Interview questions

Output question: what does this print?

An output-based question testing hoisting and the event loop.

advanced Experienced

Output-based questions test whether you truly understand execution order. Read the snippet in the code tab and predict the output before revealing it.

Sync code is the main act, microtasks are the encore, and macrotasks are the after-party — always in that order.

Key concepts

1
The key ideas being tested: synchronous code runs first, microtasks (promise callbacks) drain before macrotasks (setTimeout), and var inside the function is hoisted.
microtasksmacrotaskssetTimeoutvar
2
Answer: start, end, promise, timeout. The two console.log calls run synchronously, then the resolved promise's callback (microtask), then the timer callback (macrotask).
Answer:startendpromisetimeout