Bird
0
0

Why does process.nextTick callbacks run before setTimeout callbacks even if both are scheduled in the same phase?

hard📝 Conceptual Q10 of 15
Node.js - Timers and Scheduling
Why does process.nextTick callbacks run before setTimeout callbacks even if both are scheduled in the same phase?
AnextTick callbacks run in the timers phase
BsetTimeout callbacks have higher priority than nextTick
CsetTimeout callbacks run before nextTick callbacks
DnextTick callbacks run immediately after current operation, before event loop continues
Step-by-Step Solution
Solution:
  1. Step 1: Understand nextTick behavior

    process.nextTick callbacks run immediately after the current JavaScript operation completes, before the event loop continues.
  2. Step 2: Compare with setTimeout callbacks

    setTimeout callbacks run in the timers phase of the event loop, which happens after nextTick callbacks.
  3. Final Answer:

    nextTick callbacks run immediately after current operation, before event loop continues -> Option D
  4. Quick Check:

    nextTick runs before event loop phases [OK]
Quick Trick: nextTick runs before event loop phases, setTimeout after [OK]
Common Mistakes:
  • Thinking setTimeout runs before nextTick
  • Confusing phases with microtasks
  • Assuming nextTick runs in timers phase

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Node.js Quizzes