JavaScript Event Loop — exercises and bug fixes
5 hands-on exercises and 5 find-the-bug challenges for the JavaScript Event Loop lesson. Every one is checked automatically in the browser — write the code, run it, and the tests tell you what still fails.
Exercises(5)
- 1
Order sync and a timer
easy10 minReport the order of a synchronous line and a zero-delay timer.
- 2
Show microtasks go first
easy10 minReport that a promise handler runs before a zero-delay timer.
- 3
Order all three
easy10 minReport the full order of synchronous code, a promise and a timer.
- 4
Drain the microtask queue
easy10 minShow both promise steps run before the timer.
- 5
Show await resumes as a microtask
medium10 minReport the order of code after await against a timer.
Find the bug(5)
- 1
Fix the order read too early
easy8 minThe join runs before either queued callback has fired.
- 2
Fix the timer assumed to run first
easy8 minA promise handler is a microtask and goes before any timer.
- 3
Fix the report placed in the promise
easy8 minThe timer runs last, so the report belongs there.
- 4
Fix the second microtask missed
easy8 minBoth then steps run before the timer, so both belong in the order.
- 5
Fix await assumed to block
easy8 minCode after await resumes later, so the synchronous line goes first.
Ready to write the code?
The editor, the automatic checks and the worked solutions open up with an account.
Open the workspace