A test-first course for core JavaScript. Inspired by learn_ruby, but rebuilt for JavaScript concepts and run with Vitest.
Each lab is a folder with:
index.html— instructions (open it in a browser),- a
*.test.jsfile — the tests you must make pass, - a source
.jsfile — function stubs for you to complete.
You write code until the tests go green. That's the whole game.
You need Node.js 18+ (any recent LTS is fine).
cd learning-javascript
npm installWatch mode — re-runs automatically every time you save. This is what you want open while you work:
npm testRun a single lab:
npx vitest 00_helloRun the whole suite once and exit (no watch, good for a final check or CI):
npm run test:run-
Open the course home page in a browser:
open index.html # macOS # or just double-click index.html
-
Start with 00 Hello and go in order. Each lab builds on the last.
-
For each lab:
- Read the instructions in its
index.html. - Open the lab's source file (e.g.
00_hello/hello.js). - Start the tests (
npm test) and watch them fail. - Read the failure message — it tells you exactly what's expected.
- Write the smallest code that makes the next test pass.
- Repeat until the lab is all green, then move on.
- Read the instructions in its
Some labs (Timers, Promises) are asynchronous. The tests use Vitest's fake timers where helpful, so they run instantly — no real waiting.
| # | Lab | Concepts |
|---|---|---|
| 00 | Hello | function syntax, arguments, return values |
| 01 | Math | arithmetic, precedence, division, modulo, ** |
| 02 | Control Flow | if/else, ternary, switch, truthiness |
| 03 | Loops & Recursion | for, while, recursion |
| 04 | Objects | building objects, iterating keys/values |
| 05 | Object References | shared references, copying, accidental mutation |
| 06 | Array Transform | map, filter, forEach, reduce |
| 07 | Array Mutation | sort/toSorted, push, pop, splice, slice |
| 08 | Strings | split, join, slicing, case |
| 09 | Regex | matching, capturing groups, replacing |
| 10 | Higher-Order Functions | functions as values, closures, compose |
| 11 | Scope | function vs block scope, var/let/const |
| 12 | Gotchas | == vs ===, number + string, NaN, mutation |
| 13 | Dates | the Date object, diffs, formatting |
| 14 | Timers | setTimeout, setInterval |
| 15 | Promises | async/await, rejecting, Promise.all/race/allSettled |
| 16 | Fetching Data | fetch, JSON, transforming / filtering / paginating API data |
| 17 | Writing Tests | you write the tests and the code: matchers, edge cases, Arrange-Act-Assert |
- When stuck, read the test file. It is the precise spec.
console.logfreely — Vitest shows your output.- When in doubt, try it in the Node REPL: run
nodeand experiment. - Google the error message. Seriously.