JavaScript, by example
Modern JavaScript through runnable, annotated examples - from first principles to production-grade patterns.
43 lessons · Updated 2026-07-07
- 01Hello, WorldThe simplest JavaScript program - print a message to the console.
- 02ValuesJavaScript has seven primitive types plus the object type - and one infamous typeof quirk.
- 03VariablesThree ways to declare variables in JavaScript - var, let, and const - each with different scoping and hoisting rules.
- 04Constantsconst locks the binding, not the value - objects and arrays declared with const are still mutable.
- 05NumbersEvery non-BigInt number in JavaScript is a 64-bit float - understanding the precision limits prevents hard-to-debug arithmetic bugs.
- 06StringsA string is text. JavaScript has several ways to create and combine strings, with template literals being the most flexible option.
- 07Unicode StringsEmoji, accents, and other Unicode text can make string length and equality more surprising than they look on screen.
- 08BooleansThe true/false type - including the eight falsy values, truthy coercion, and why == is a trap you should never step in.
- 09Conditionalsif/else, ternary, logical operators as control flow, and switch case
- 10Loopsfor, for-of, for-in, forEach - which to use and why forEach can't be awaited.
- 11FunctionsWriting reusable blocks of code with names, parameters, return values, declarations, and expressions.
- 12Function Parameters and thisDefault parameters, rest parameters, and the dynamic this value that regular functions receive from the call site.
- 13Arrow FunctionsShorter syntax and lexical `this` - plus when arrow functions are the wrong choice.
- 14ClosuresFunctions that remember the variables from their defining scope - the backbone of private state, memoization, and the module pattern.
- 15ArraysOrdered lists of values, zero-based indexes, length, push, pop, and the mutation rule beginners need first.
- 16Array Transformsmap, filter, and reduce turn arrays into new values without mutating the original list.
- 17Array Search and Sortfind, some, every, flat, flatMap, and the numeric sort comparator that prevents string-order bugs.
- 18Higher-Order Functions and CallbacksFunctions that accept or return other functions - the pattern behind map, filter, and every event listener you've ever written.
- 19ObjectsLiterals, shorthand, computed keys, spread, destructuring, and JSON serialization quirks.
- 20Maps and SetsKeyed collections that accept any value as a key (Map) and deduplicated collections (Set) - when to reach for them instead of plain objects and arrays.
- 21ModulesES module import/export, default vs named exports, circular imports, and CJS interop.
- 22Promises and async/awaitAsync control flow with async functions, await, try/catch, serial loops, and parallel mapping.
- 23Promise CombinatorsPromise.all, allSettled, race, and any give you different ways to coordinate many async operations.
- 24Classes and `this`The class syntax, constructors, instance properties, and methods shared through JavaScript's prototype system.
- 25Class Method BindingClass methods lose their this value when detached from the instance, so callbacks need binding or an arrow wrapper.
- 26RecursionFunctions that call themselves - the natural fit for tree traversal, with a hard stack limit that matters on user-supplied data.
- 27DatesCreating, comparing, and formatting dates with the built-in Date object, and why you should store epoch milliseconds or ISO strings and format at the edge.
- 28DOM ManipulationHow JavaScript reads and mutates the live HTML tree - selecting nodes, changing content and classes, and creating elements safely without opening an XSS hole.
- 29EventsAttaching listeners, reading the event object, and cleaning up with AbortController to avoid the memory leaks that forgotten removeEventListener leaves behind.
- 30Form ValidationChecking user input before submission - HTML-native constraints, JavaScript custom messages, and the server-must-re-validate rule that client validation never replaces.
- 31DebounceWaiting until rapid events pause, preserving the caller's this value when a debounced method still needs its object context.
- 32Leading DebounceRun the first trigger immediately, then ignore repeated triggers until the debounce window clears.
- 33Accessibility BasicsMaking interactive elements work for keyboard users and screen readers by choosing semantic HTML first.
- 34Focus and ARIAMove focus after dynamic DOM changes and use ARIA labels or descriptions only when native HTML does not say enough.
- 35localStorage and sessionStorageBrowser key-value storage that survives page reloads - what it stores, what it doesn't, and why auth tokens and PII must never go near it.
- 36CRUD with localStorageCRUD on a JSON-encoded list stored in a single localStorage key - including try/catch on parse and versioned keys to survive schema changes between app deploys.
- 37Regular ExpressionsRegular expressions match and transform text using patterns built into JS - write them as /foo/ literals or new RegExp("foo"), with flags like g (global) and i (case-insensitive).
- 38Stacks and QueuesStack (LIFO: push/pop) and queue (FIFO: push/shift). Arrays are great stacks but poor queues because shift is O(n); use a linked-list queue when throughput matters.
- 39Linked ListsLinked list: nodes chained through next pointers. Prepend is O(1), while append and lookup require walking the chain.
- 40Linked List Random AccessLinked lists cannot jump to index i. They must walk from the head, which is why arrays win for most indexed reads.
- 41TreesTree: a hierarchy with one root where each node has a value and children. Recursive traversal is elegant but unsafe on deep user data; use iterative DFS with an explicit stack.
- 42GraphsGraph: nodes connected by edges, with cycles and multiple paths. Always carry a visited Set or a cycle will infinite-loop your traversal. Adjacency lists are the right default.
- 43ThrottleCapping how often a hot handler runs, so scroll, resize, and pointer events can keep updating without flooding the app.
Enjoyed this? Get more software craft delivered to your inbox.