Bird
0
0

Why does this code never print 'Done'?

medium📝 Debug Q7 of 15
Node.js - Timers and Scheduling
Why does this code never print 'Done'?
function loop() {
  process.nextTick(loop);
}
loop();
console.log('Done');
Aconsole.log is inside the loop function and never called
Bprocess.nextTick keeps scheduling loop before console.log runs
Cprocess.nextTick is asynchronous and delayed
Dloop function has syntax error
Step-by-Step Solution
Solution:
  1. Step 1: Understand process.nextTick scheduling

    It schedules loop to run before any I/O or timers.
  2. Step 2: Analyze event loop blocking

    loop keeps rescheduling itself, blocking the event loop from reaching console.log.
  3. Final Answer:

    process.nextTick keeps scheduling loop before console.log runs -> Option B
  4. Quick Check:

    nextTick recursion blocks event loop [OK]
Quick Trick: nextTick recursion blocks other code from running [OK]
Common Mistakes:
  • Thinking console.log is inside loop
  • Assuming nextTick delays execution
  • Believing syntax error exists

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Node.js Quizzes