Bird
0
0

What will be the output order of this Node.js code?

medium📝 Predict Output Q4 of 15
Node.js - Timers and Scheduling
What will be the output order of this Node.js code?
console.log('A');
setTimeout(() => console.log('B'), 0);
process.nextTick(() => console.log('C'));
console.log('D');
AA C D B
BA C B D
CA D B C
DA D C B
Step-by-Step Solution
Solution:
  1. Step 1: Identify synchronous logs

    'A' and 'D' log immediately in order.
  2. Step 2: Understand process.nextTick and setTimeout order

    process.nextTick runs before timers, so 'C' logs before 'B'.
  3. Final Answer:

    A C D B -> Option A
  4. Quick Check:

    Output order = A C D B [OK]
Quick Trick: process.nextTick runs before setTimeout even with zero delay [OK]
Common Mistakes:
  • Assuming setTimeout runs before nextTick
  • Mixing synchronous and async order
  • Ignoring zero delay meaning

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Node.js Quizzes