Skip to content
JavaScript·Intermediate·Output based·1 min read

What order does console.log produce for synchronous code, a resolved promise, and a timer?

Short interview answer

Synchronous logs run first. The resolved promise reaction runs as a microtask after the current script task. The timer runs as a later task, assuming no earlier work. The useful explanation is queue semantics, not memorizing one puzzle.

Example

JavaScript
console.log('A');setTimeout(() => console.log('B'));        // macrotaskPromise.resolve().then(() => console.log('C')); // microtaskconsole.log('D');
// Output: A  D  C  B// sync (A, D) -> drain microtasks (C) -> next task (B)

Key takeaway

Explain the underlying mental model clearly, then support it with a concrete example and its trade-offs.

← Back to Event loop

Related questions