Bird
0
0

What happens if you call setTimeout with a delay of 0 milliseconds in Node.js?

easy📝 Conceptual Q2 of 15
Node.js - Timers and Scheduling
What happens if you call setTimeout with a delay of 0 milliseconds in Node.js?
AThe callback runs immediately before any other code
BThe callback runs after at least one event loop iteration
CThe callback runs in the next tick phase
DThe callback is ignored
Step-by-Step Solution
Solution:
  1. Step 1: Understand setTimeout with 0 delay

    Even with 0 ms delay, setTimeout schedules the callback to run after the timers phase in the next event loop iteration.
  2. Step 2: Clarify timing behavior

    The callback does not run immediately or in the next tick phase; it waits for the timers phase in the next loop cycle.
  3. Final Answer:

    The callback runs after at least one event loop iteration -> Option B
  4. Quick Check:

    setTimeout(0) delays to next loop iteration [OK]
Quick Trick: setTimeout(0) waits for next timers phase, not immediate [OK]
Common Mistakes:
  • Thinking 0 delay means immediate execution
  • Confusing with process.nextTick
  • Assuming callback runs before current code finishes

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Node.js Quizzes