0
0
Node.jsframework~20 mins

Event loop mental model in Node.js - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Event Loop Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
What is the output order of this Node.js code?
Consider this Node.js code snippet. What will be the order of the printed lines in the console?
Node.js
console.log('Start');
setTimeout(() => console.log('Timeout'), 0);
Promise.resolve().then(() => console.log('Promise'));
console.log('End');
A"Start", "Promise", "End", "Timeout"
B"Promise", "Start", "End", "Timeout"
C"Start", "Timeout", "Promise", "End"
D"Start", "End", "Promise", "Timeout"
Attempts:
2 left
💡 Hint
Remember that promises run before timers even if the timer delay is zero.
state_output
intermediate
2:00remaining
What is the final value of counter after this code runs?
Given this Node.js code, what is the final value of the variable counter after all asynchronous tasks complete?
Node.js
let counter = 0;
setTimeout(() => { counter += 1; }, 0);
Promise.resolve().then(() => { counter += 2; });
counter += 3;
A6
B3
C5
D2
Attempts:
2 left
💡 Hint
Synchronous code runs first, then microtasks, then timers.
📝 Syntax
advanced
2:00remaining
Which option causes a SyntaxError in this async code?
Identify which code snippet will cause a SyntaxError when run in Node.js 20+.
Aasync function test() { await 5; }
Basync function test() { return await 5; }
Casync function test() { await; }
Dconst test = async () => { await Promise.resolve(); };
Attempts:
2 left
💡 Hint
The await keyword must be followed by an expression.
🔧 Debug
advanced
2:00remaining
Why does this code never print 'Done'?
Examine the code below. Why does it never print 'Done' to the console?
Node.js
setImmediate(() => {
  while(true) {}
  console.log('Done');
});
A'setImmediate' callbacks never run in Node.js.
BThe infinite loop blocks the event loop, so 'Done' is never reached.
CThe console.log is outside the callback function.
DThe code throws a ReferenceError before running.
Attempts:
2 left
💡 Hint
Think about what happens when the event loop is blocked.
🧠 Conceptual
expert
2:00remaining
Which statement best describes the Node.js event loop phases?
Select the option that correctly orders the main phases of the Node.js event loop.
ATimers → Pending Callbacks → Poll → Check → Close Callbacks
BPoll → Timers → Check → Pending Callbacks → Close Callbacks
CTimers → Poll → Pending Callbacks → Check → Close Callbacks
DCheck → Timers → Poll → Pending Callbacks → Close Callbacks
Attempts:
2 left
💡 Hint
Remember the event loop starts with timers phase.