JavaScript Lab Examples

Standalone, commented demos that follow the track's lesson order, grouped by phase. Every demo is a single file; language demos run with Node, browser demos run in place.

Phase 2 — Foundations: running JavaScript

Demos 01–08 pair with the Foundations phase: how code reaches the browser, and the first interactive programs. JS files run with node <file>; HTML files open in place.

#DescriptionSourcePreview
01Your first line of JavaScript, in the browser console01_hello_console.htmlopen
02Running a file with Node instead of the console02_first_file.js—
03Triggering your first error messages — on purpose03_errors_on_purpose.js—
04Inline script: JavaScript embedded in a page04_script_inline.htmlopen
05External script: separating app code from markup05_app.js · 05_script_external.htmlopen
06defer versus async: load-order timing, visualized06_defer_vs_async.htmlopen
07ES modules: splitting code across files07_modules/open
08The first event listener: a click counter08_click_counter.htmlopen

Phase 2 — Foundations: the language model

Demos 09–21 exercise values, control flow, functions, and the collection types — each is a predict-then-run lab with the expected output in the comments.

#DescriptionSourcePreview
09typeof tour: the value types09_values_and_types.js—
10Coercion traps: ==, +, and falsy values10_coercion_lab.js—
11Strings: template literals and the method toolbox11_strings_lab.js—
12Control flow: branching and loops, interactive12_control_flow.htmlopen
13Functions: parameters, returns, and arrow syntax13_functions_lab.js—
14Closures: functions that remember, visualized14_closures.htmlopen
15Objects: references versus copies15_objects_lab.js—
16Arrays: map, filter, reduce in practice16_arrays_lab.js—
17Map and Set: collections with any key type17_collections_lab.js—
18Classes: state, methods, and inheritance18_classes_lab.js—
19this binding: the four rules in one file19_this_binding.js—
20A module project: logger, utils, main — wired together20_modules_lab/open
21Prototype pollution: mutating the shared chain, and the damage21_prototype_pollution.js—

Phase 3 — Runtime: errors, DOM, debugging

Demos 22–26 pair with the Runtime phase: the error system, the engine's stack and heap, the DOM, platform APIs, and DevTools. JS demos run with node; the HTML labs are interactive.

#DescriptionSourcePreview
22Errors lab: every error type triggered, caught by class, plus a custom ValidationError22_errors_lab.js—
23Runtime lab: call-stack depth, a deliberate stack overflow, stack vs heap, a measurable leak23_runtime_lab.js—
24DOM lab: build a list with textContent and event delegation24_dom_lab.htmlopen
25Storage lab: strings-only round trips through localStorage and JSON25_storage_lab.htmlopen
26DevTools lab: catch a planted string-concatenation bug with breakpoints only26_devtools_lab.htmlopen

Phase 4 — Async: the event loop, promises, iteration, workers

Demos 27–30 pair with the Async phase: the two-queue execution model, promise mechanics and traps, generators as lazy pipelines, and real parallelism with worker threads. All four run with node.

#DescriptionSourcePreview
27Event-loop lab: sync vs microtask vs macrotask ordering, plus a visible starvation block27_event_loop_lab.js—
28Promises lab: settlement, chain error paths, the four combinators, and the floating-promise trap28_promises_lab.js—
29Generators lab: the iterator protocol, lazy infinite sequences, yield*, for await…of29_generators_lab.js—
30Workers lab: serial vs parallel CPU-bound blocks, zero-copy buffer transfer, measured speedup30_workers_lab.js—
31Scheduling lab: raw vs throttled vs debounced handlers, visualized; frame budget31_scheduling_lab.htmlPreview

Phase 5 — Practice: tested bank, store counter, worker pool

#DescriptionSourcePreview
32The tested bank: a full node:test suite — hooks, nested tests, rejection assertions, immutability proof32_node_test_demo.js—
33Store counter: the same app twice — DOM-as-state versus one-way data flow with undo33_store_counter.htmlPreview
34Worker pool: N long-lived worker_threads, a job queue, promise-per-job — and the timing to prove it34_worker_pool_sample.js—

How to study them

Open the source in the code viewer, change one line, predict what changes, then verify — in the terminal for Node demos, in the preview for browser demos.