Bird
0
0

What is the main difference between setInterval and recursive setTimeout in Node.js?

easy📝 Conceptual Q11 of 15
Node.js - Timers and Scheduling
What is the main difference between setInterval and recursive setTimeout in Node.js?
A<code>setInterval</code> can only run synchronous code, recursive <code>setTimeout</code> can run asynchronous code.
B<code>setInterval</code> runs tasks at fixed intervals regardless of task duration, recursive <code>setTimeout</code> waits for the task to finish before scheduling the next.
C<code>setInterval</code> runs only once, recursive <code>setTimeout</code> runs repeatedly.
D<code>setInterval</code> automatically adjusts intervals based on task duration, recursive <code>setTimeout</code> does not.
Step-by-Step Solution
Solution:
  1. Step 1: Understand setInterval behavior

    setInterval schedules a function to run repeatedly at fixed time intervals without waiting for the previous run to finish.
  2. Step 2: Understand recursive setTimeout behavior

    Recursive setTimeout schedules the next run only after the current function completes, avoiding overlap.
  3. Final Answer:

    setInterval runs tasks at fixed intervals regardless of task duration, recursive setTimeout waits for the task to finish before scheduling the next. -> Option B
  4. Quick Check:

    Task overlap control [OK]
Quick Trick: Remember: recursive waits, interval runs fixed times [OK]
Common Mistakes:
  • Thinking setInterval waits for task completion
  • Confusing recursive setTimeout with single timeout
  • Assuming setInterval adjusts timing automatically

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Node.js Quizzes