Bird
0
0

Why is it important to store the return value of setInterval in a variable?

hard📝 Conceptual Q10 of 15
Node.js - Timers and Scheduling
Why is it important to store the return value of setInterval in a variable?
ABecause the return value is the timer ID needed to stop the interval with clearInterval
BBecause setInterval returns the number of times the function has run
CBecause setInterval returns a promise that must be awaited
DBecause setInterval returns the function passed to it
Step-by-Step Solution
Solution:
  1. Step 1: Identify what setInterval returns

    It returns a timer ID, a unique identifier for the interval.
  2. Step 2: Purpose of timer ID

    This ID is required by clearInterval to stop the correct timer.
  3. Final Answer:

    Because the return value is the timer ID needed to stop the interval with clearInterval -> Option A
  4. Quick Check:

    Timer ID from setInterval is needed to clearInterval [OK]
Quick Trick: Store timer ID to clearInterval later [OK]
Common Mistakes:
  • Thinking setInterval returns count or promise
  • Not storing timer ID and unable to clear timer
  • Confusing return value with function argument

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Node.js Quizzes