Skip to content

Agilefreaks/learning-javascript

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

# 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

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

No releases published

Packages

 
 
 

Contributors