Bird
0
0

Identify the error in this code snippet:

medium📝 Debug Q6 of 15
Node.js - Timers and Scheduling
Identify the error in this code snippet:
process.nextTick(console.log('Hello'));
setImmediate(() => console.log('World'));
ANo error, code runs correctly
BsetImmediate callback is missing parentheses
Cprocess.nextTick cannot be used with console.log
Dprocess.nextTick is called with the result of console.log, not a function
Step-by-Step Solution
Solution:
  1. Step 1: Analyze process.nextTick argument

    The code calls console.log('Hello') immediately and passes its result (undefined) to process.nextTick, which expects a function.
  2. Step 2: Check setImmediate usage

    setImmediate is correctly passed a function, so no error there.
  3. Final Answer:

    process.nextTick is called with the result of console.log, not a function -> Option D
  4. Quick Check:

    Callback must be a function = A [OK]
Quick Trick: Always pass a function, not the result, to nextTick [OK]
Common Mistakes:
  • Calling the function instead of passing it
  • Assuming no error with immediate call
  • Confusing function reference and invocation

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Node.js Quizzes