JavaScript Koans
JavaScript is the language every web browser understands. It makes pages interactive, and it runs on servers and in tools and apps too. It’s flexible and forgiving: functions are values, objects are everywhere, and much of its power is in handling things that happen later, like clicks and network replies. These koans start with its values and famous quirks, and go on to arrays and objects, closures, classes, iterators and async code.
89 koans in 16 groups, tested with Vitest. Each is a small program whose tests fail: replace every ___ until they pass.
Awakening
How a koan checks your answers, and how JavaScript compares and checks values.
Numbers
One number type for integers and fractions, its surprises, and BigInt.
Strings
Template literals, slicing, methods, Unicode, and regular expressions.
- Template literals
- Indexing and slicing
- String methods
- Split, join and pad
- Comparing strings
- Unicode
- Regular expressions
Variables and scope
let, const and var, blocks, and hoisting.
Control flow
Choosing and repeating: if, switch, the loops, break and continue, and the operators that short-circuit.
Arrays
Lists of values: changing them, copying them, searching and transforming them.
- Arrays
- Slice and splice
- Map, filter and reduce
- Searching
- Sorting
- Copying arrays
- Iterating arrays
- Building arrays
- Grouping
Objects
Keyed data: building objects, taking them apart, copying, freezing, and reading safely.
- Objects
- Shorthand and computed keys
- Spread and rest
- Object methods
- Getters and setters
- Freezing
- Optional chaining and nullish
Maps, sets and symbols
The collections built for keyed data and unique values, and symbols.
Functions
Functions as values: declarations, arrows, parameters, closures, this, and recursion.
Classes and prototypes
Classes, inheritance, private fields, and the prototypes underneath.
Iterators and generators
The iteration protocol, generator functions, and making your own iterables.
Async
Promises, async functions, combinators, errors, and the event loop.
Errors
Catching, cleaning up, your own errors, and causes.
JSON, dates and Intl
Data in and out: JSON, dates, and formatting for people.
Metaprogramming
Code about code: proxies, Reflect, and tagged templates.
Puzzles
Small programs that put the path together: read them closely and predict what they do.