Skip to main content
JavaScript Interview Questions Predict Output P0 Hard

Promise chain vs queued microtasks and timer

Assume a single browser task. Write each log in order.

Official Reference

Code Snippet

console.log("start");
setTimeout(() => console.log("timer"), 0);
const ready = new Promise(resolve => {
  console.log("executor");
  resolve();
});
ready.then(() => {
  console.log("then 1");
  queueMicrotask(() => console.log("inner"));
}).then(() => console.log("then 2"));
queueMicrotask(() => console.log("outer"));
console.log("end");

Expected Output & Explanation

start
executor
end
then 1
outer
inner
then 2
timer

The executor runs inline. then 1 queues inner before the chained then 2 becomes eligible, but outer is already waiting ahead of both. The timer runs after the microtask queue drains.

Module Context & References

JavaScript · Async output drills Trace microtasks, promise identity, thenables and error recovery
Personal Notes · Markdown

Technologies & Interview Topics Covered

Switch between short-term interview tracks and long-term 80/20 engineering depth to practice JavaScript internals, React rendering and hooks, timed frontend machine coding UI challenges, MeetaPro FG300, Blind 75 & NeetCode 150 DSA patterns, Python & FastAPI APIs, PostgreSQL query optimization & MVCC, Redis caching, Applied AI RAG pipelines & evaluations, and distributed system design.