Bird
0
0

Which of the following is the correct syntax to start a repeating timer that logs "Hello" every 2 seconds?

easy📝 Syntax Q3 of 15
Node.js - Timers and Scheduling
Which of the following is the correct syntax to start a repeating timer that logs "Hello" every 2 seconds?
AsetInterval(console.log('Hello'), 2000);
BsetInterval(console.log, 2000);
CsetInterval(() => console.log('Hello'), 2000);
DsetInterval(console.log('Hello'), '2000');
Step-by-Step Solution
Solution:
  1. Step 1: Understand function argument in setInterval

    The first argument must be a function, here an arrow function that calls console.log.
  2. Step 2: Check interval argument type

    The second argument is the interval in milliseconds as a number, 2000 for 2 seconds.
  3. Final Answer:

    setInterval(() => console.log('Hello'), 2000); -> Option C
  4. Quick Check:

    Function + number interval = correct syntax [OK]
Quick Trick: Pass a function and number milliseconds to setInterval [OK]
Common Mistakes:
  • Calling console.log immediately instead of passing a function
  • Passing interval as string instead of number
  • Missing arrow function wrapper

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Node.js Quizzes