JavaScript Concepts
Visual explanations of the ideas behind the problems.
Fundamentals: Part 1
JavaScript has a small set of built-in types, and it converts between them automatically when an operator expects a different one.
When an expression mixes operators, precedence decides which one runs first, and associativity decides the order among operators of equal precedence.
Fundamentals: Part 2
let and const are block-scoped and unreachable until their line runs, while var is function-scoped and available as undefined from the top.
Every value is truthy unless it is one of a short, memorizable list of falsy values.
Behind the Scenes
JavaScript sets up all your declarations before it runs a single line of your code.
A variable lookup walks outward through nested scopes until it finds a match or runs out of places to look.
this is not fixed to a function; it is decided fresh by how that function gets called.
Every function call gets its own frame on a stack, and JavaScript only ever runs the frame on top.
Copying a number copies the value; copying an object copies a pointer to the same shared value.
Data Structures, Operators & Strings
Destructuring unpacks values from an array or an object straight into named variables.
The same ... syntax expands a value out in one context and gathers values together in the other.
?. stops a property lookup safely at the first null or undefined instead of throwing; ?? picks a default only for null or undefined.
A Set stores unique values with no duplicates; a Map stores key-value pairs with keys of any type and fast lookup.
A Closer Look at Functions
A function keeps access to the variables it was born in, even after that scope returns.
A function that takes another function in, gives one back out, or both.
Turning a multi-argument function into a chain of one-argument functions.
Three ways to control what this refers to when a function runs.
Working With Arrays
Object-Oriented Programming
When an object does not have a property itself, JavaScript looks for it on the object's prototype instead.
A class is syntax on top of a constructor function and its prototype, not a new kind of object.
A getter runs code when a property is read, and a setter runs code when a property is assigned.
Asynchronous JavaScript
The engine finishes the current script, drains every pending microtask, then runs one task from the macrotask queue, on repeat.
A promise is a placeholder for a value that starts pending and settles exactly once, to fulfilled or rejected.
await pauses an async function until a promise settles, without blocking the rest of the program.
Microtasks, like promise callbacks, always run before the next macrotask, like a setTimeout, even a zero-delay one.