Node.js - Timers and SchedulingWhich 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');Check Answer
Step-by-Step SolutionSolution:Step 1: Understand function argument in setIntervalThe first argument must be a function, here an arrow function that calls console.log.Step 2: Check interval argument typeThe second argument is the interval in milliseconds as a number, 2000 for 2 seconds.Final Answer:setInterval(() => console.log('Hello'), 2000); -> Option CQuick 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 functionPassing interval as string instead of numberMissing arrow function wrapper
Master "Timers and Scheduling" in Node.js9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallPerf
More Node.js Quizzes Child Processes - Child process exit codes - Quiz 5medium Child Processes - Handling child process errors - Quiz 11easy Child Processes - fork for Node.js child processes - Quiz 13medium Debugging and Profiling - CPU profiling basics - Quiz 14medium Debugging and Profiling - Node.js built-in debugger - Quiz 11easy Timers and Scheduling - setTimeout and clearTimeout - Quiz 4medium Timers and Scheduling - setTimeout and clearTimeout - Quiz 12easy URL and Query String Handling - URLSearchParams for query strings - Quiz 13medium URL and Query String Handling - URL class for parsing - Quiz 13medium Worker Threads - Passing data to workers - Quiz 10hard