Skip to content

Repository files navigation

Event Loop

A JavaScript event-loop ordering challenge. Fourteen scenarios schedule work with promises, setTimeout, queueMicrotask, async/await, thenables, rejections, process.nextTick, requestAnimationFrame, and MessageChannel — your job is to predict the exact order the logs fire, before running anything.

There are two ways to play: a React web app with live grading and a queue visualizer, or a Node game driven by the Vitest suite. The full challenge guide lives in src/exercises/event-loop-order/README.md.

Prerequisites

  • Node v24.18.0 — pinned in .nvmrc
  • pnpm 11.20.0 — pinned via the packageManager field in package.json

Running the web app

From the repository root:

# 1. Use the pinned Node version
nvm use

# 2. Activate the pinned pnpm version (via Corepack, bundled with Node)
corepack enable

# 3. Install dependencies
pnpm install

# 4. Start the dev server
pnpm dev

Then open the URL Vite prints (by default http://localhost:5173). Pick a scenario, click the labels into your predicted order, and hit Run & grade. Progress is saved in localStorage.

To build and serve a production bundle instead:

pnpm build
pnpm preview

Playing the Node game

Write your predicted orders in src/exercises/event-loop-order/predictions.ts, then let the tests grade you:

pnpm test         # run the suite once
pnpm test:watch   # re-grade on every save

All commands

Command What it does
pnpm dev Start the Vite dev server for the web app
pnpm build Build the production bundle to dist/
pnpm preview Serve the production bundle locally
pnpm test Run the Vitest suite once
pnpm test:watch Run Vitest in watch mode
pnpm test:coverage Run tests with V8 coverage (reports to coverage/)
pnpm typecheck Type-check with tsc --noEmit
pnpm reveal:event-loop Print every scenario's actual order (spoilers)

License

MIT

About

JavaScript event-loop ordering challenge: predict execution order across 14 scenarios, with a React visualizer and Vitest-graded mode

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages