Node.js Fundamentals · The Node Runtime · Lesson 3 of 13
The Node Event Loop
Concept
The Node Event Loop
Node runs JavaScript on a single thread but handles input and output asynchronously via an event loop, so slow operations do not block everything else.
By the end of this lesson
- Explain the core idea behind The Node Event Loop.
- Predict output before running a change.
- Test one realistic and one unusual input.
- Use the result to make the next decision.
How to study this page
- 1. Read one concept.
- 2. Change the example.
- 3. Run, compare, and explain.
- 4. Complete the challenge below.
ExampleRunnable
console.log("1");
setTimeout(() => console.log("2"), 0);
console.log("3");Try it Yourself »Self-check before continuing
Without looking at the example, describe what changes when you modify one input in The Node Event Loop. Then reopen the editor and prove your explanation with a small test.
You are ready to continue when you can predict, test, and explain the result.
Your turn
Predict the output order of the code above before running it.
Loading editor…
Console