Bird
0
0

Identify the error in this code snippet:

medium📝 Debug Q14 of 15
Node.js - Timers and Scheduling
Identify the error in this code snippet:
setTimeout(console.log('Hello'), 1000);
AThe delay argument is missing
BThe delay must be 0 or less
Cconsole.log is called immediately instead of after 1000ms
DsetTimeout requires a string as first argument
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the first argument of setTimeout

    console.log('Hello') is called immediately, returning undefined, which is passed to setTimeout.
  2. Step 2: Understand correct usage

    setTimeout expects a function as first argument, not the result of a function call.
  3. Final Answer:

    console.log is called immediately instead of after 1000ms -> Option C
  4. Quick Check:

    Function call inside setTimeout runs immediately [OK]
Quick Trick: Pass a function, not a function call, to setTimeout [OK]
Common Mistakes:
  • Thinking delay argument is missing
  • Passing string instead of function
  • Believing delay must be zero or negative

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Node.js Quizzes