Skip to content

Repository files navigation

Learning JavaScript

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.js file — the tests you must make pass,
  • a source .js file — function stubs for you to complete.

You write code until the tests go green. That's the whole game.

Setup

You need Node.js 18+ (any recent LTS is fine).

cd learning-javascript
npm install

Running the tests

Watch mode — re-runs automatically every time you save. This is what you want open while you work:

npm test

Run a single lab:

npx vitest 00_hello

Run the whole suite once and exit (no watch, good for a final check or CI):

npm run test:run

How to use the course

  1. Open the course home page in a browser:

    open index.html # macOS# or just double-click index.html
  2. Start with 00 Hello and go in order. Each lab builds on the last.

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

Some labs (Timers, Promises) are asynchronous. The tests use Vitest's fake timers where helpful, so they run instantly — no real waiting.

Course outline

#LabConcepts
00Hellofunction syntax, arguments, return values
01Matharithmetic, precedence, division, modulo, **
02Control Flowif/else, ternary, switch, truthiness
03Loops & Recursionfor, while, recursion
04Objectsbuilding objects, iterating keys/values
05Object Referencesshared references, copying, accidental mutation
06Array Transformmap, filter, forEach, reduce
07Array Mutationsort/toSorted, push, pop, splice, slice
08Stringssplit, join, slicing, case
09Regexmatching, capturing groups, replacing
10Higher-Order Functionsfunctions as values, closures, compose
11Scopefunction vs block scope, var/let/const
12Gotchas== vs ===, number + string, NaN, mutation
13Datesthe Date object, diffs, formatting
14TimerssetTimeout, setInterval
15Promisesasync/await, rejecting, Promise.all/race/allSettled
16Fetching Datafetch, JSON, transforming / filtering / paginating API data
17Writing Testsyou write the tests and the code: matchers, edge cases, Arrange-Act-Assert

Tips

  • When stuck, read the test file. It is the precise spec.
  • console.log freely — Vitest shows your output.
  • When in doubt, try it in the Node REPL: run node and experiment.
  • Google the error message. Seriously.

About

Mixed exercises for javascript core concepts

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages