0
0
Node.jsframework~10 mins

Event loop mental model in Node.js - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to schedule a function to run after the current event loop phase.

Node.js
setTimeout(() => { console.log('Hello'); }, [1]);
Drag options to blanks, or click blank then click option'
A0
B1000
Cnull
D-1
Attempts:
3 left
💡 Hint
Common Mistakes
Using negative or null values for delay causes errors or unexpected behavior.
2fill in blank
medium

Complete the code to add a callback to the next tick queue.

Node.js
process.[1](() => { console.log('Next tick'); });
Drag options to blanks, or click blank then click option'
AnextTick
BsetInterval
CsetTimeout
DsetImmediate
Attempts:
3 left
💡 Hint
Common Mistakes
Using setImmediate or setTimeout delays the callback to later phases.
3fill in blank
hard

Fix the error in the code to correctly schedule a callback after the current timers phase.

Node.js
setImmediate(() => { console.log('Immediate'); });
setTimeout(() => { console.log('Timeout'); }, [1]);
Drag options to blanks, or click blank then click option'
A-1
B0
Cundefined
Dnull
Attempts:
3 left
💡 Hint
Common Mistakes
Using null or negative values for timeout delay.
4fill in blank
hard

Fill both blanks to create a map of timers with delays and their callback names.

Node.js
const timers = { [1]: 'first', [2]: 'second' };
Drag options to blanks, or click blank then click option'
A100
BsetTimeout
C200
DsetImmediate
Attempts:
3 left
💡 Hint
Common Mistakes
Using function names as keys instead of numbers.
5fill in blank
hard

Fill all three blanks to create a filtered object of callbacks with delays greater than 100.

Node.js
const filtered = Object.entries(timers).reduce((acc, [[1], [2]]) => {
  if ([1] [3] 100) {
    acc[[1]] = [2];
  }
  return acc;
}, {});
Drag options to blanks, or click blank then click option'
Adelay
Bcb
C>
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong variable names or wrong comparison operators.