How would you explain Promise callbacks versus setTimeout ordering?
Understand the idea, explain it in your own words and use the rubric to find your next learning gap.
The idea behind the question
Synchronous code runs first. Promise reactions use the microtask queue, while timer callbacks run in later tasks when eligible; a zero delay is not an immediate execution guarantee.
Log A, schedule a zero-delay timer, schedule a resolved Promise callback, then log B.
A practical way to learn it
Predict console order for A, B, a Promise callback and a timer, then run the sample.
Open JavaScript playgroundThe related tool opens separately; your interview answer stays here. Written practice is self-guided, without automatic code grading.
Build an explanation you understand
- State what the concept does in plain language.
- Apply it to the example and make your assumptions explicit.
- Explain a trade-off, failure case and how you would test it.
- Distinguish your actual experience from a proposed approach.
How would you explain it?
Single-question timers reset on refresh. Full mock sessions can resume from this browser.
Strengthen your explanation
Compare reasoning, not identical wording. Reference answers describe a possible approach; replace hypothetical statements with truthful details from your own work.
One way to answer
I would trace the synchronous stack first, then the queued work rather than guessing from the numerical timer delay. In the simple example, A and B print before the resolved Promise reaction, and the eligible timer runs later. I would clarify that real applications also have rendering, I/O and other queued work, so timing is not a performance guarantee. Long synchronous work and a stream of microtasks can delay responsiveness. I would test a small reproduction and keep platform-specific event-loop details separate.
What a strong explanation should cover
Tick only the points your own answer addresses. This is self-assessment, not AI scoring.
0 / 3 points self-reportedWatch out for
- Assuming setTimeout(fn, 0) interrupts the current function.
Now go one level deeper
- How can microtasks delay rendering?
- Would Node-specific phases change the explanation?
Further reading
Further-reading links support learning; the reference is Sukoaa-authored, not an official employer answer key.