Bird
0
0

In Node.js, why does process.nextTick run before setTimeout and setImmediate?

easy📝 Conceptual Q11 of 15
Node.js - Timers and Scheduling
In Node.js, why does process.nextTick run before setTimeout and setImmediate?
ABecause <code>process.nextTick</code> waits for a timer to expire before running.
BBecause <code>process.nextTick</code> callbacks run immediately after the current operation completes, before the event loop continues.
CBecause <code>process.nextTick</code> runs only after all I/O events finish.
DBecause <code>process.nextTick</code> schedules tasks in the next event loop cycle.
Step-by-Step Solution
Solution:
  1. Step 1: Understand Node.js event loop phases

    Node.js event loop has phases: timers, I/O callbacks, idle, poll, check, and close callbacks.
  2. Step 2: Identify when process.nextTick runs

    process.nextTick callbacks run immediately after the current operation, before the event loop continues to the next phase.
  3. Final Answer:

    Because process.nextTick callbacks run immediately after the current operation completes, before the event loop continues. -> Option B
  4. Quick Check:

    process.nextTick runs before timers and I/O [OK]
Quick Trick: Remember: nextTick runs before event loop phases start [OK]
Common Mistakes:
  • Thinking nextTick waits for timers
  • Confusing nextTick with setImmediate timing
  • Assuming nextTick runs after I/O callbacks

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Node.js Quizzes