Skip to main content

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. 1

    Order sync and a timer

    easy10 min

    Report the order of a synchronous line and a zero-delay timer.

  2. 2

    Show microtasks go first

    easy10 min

    Report that a promise handler runs before a zero-delay timer.

  3. 3

    Order all three

    easy10 min

    Report the full order of synchronous code, a promise and a timer.

  4. 4

    Drain the microtask queue

    easy10 min

    Show both promise steps run before the timer.

  5. 5

    Show await resumes as a microtask

    medium10 min

    Report the order of code after await against a timer.

Find the bug(5)

  1. 1

    Fix the order read too early

    easy8 min

    The join runs before either queued callback has fired.

  2. 2

    Fix the timer assumed to run first

    easy8 min

    A promise handler is a microtask and goes before any timer.

  3. 3

    Fix the report placed in the promise

    easy8 min

    The timer runs last, so the report belongs there.

  4. 4

    Fix the second microtask missed

    easy8 min

    Both then steps run before the timer, so both belong in the order.

  5. 5

    Fix await assumed to block

    easy8 min

    Code 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