Glossary
94 terms from JavaScript Beyond the Basics, in plain words, each with the chapter that teaches it.
#
- ?. (optional chaining)
- The `?.` operator reads a property only if the value on its left isn't `null` or `undefined`. Otherwise the whole expression gives `undefined` instead of an error, so `guest.address?.zip` is safe when Lee has no address yet.
- ?? (nullish coalescing)
- The `??` operator gives its right side only when its left side is `null` or `undefined`. Unlike `||`, it keeps values such as `0`, so a quantity of 0 stays 0.
A
- AbortSignal
- A built-in object that tells a running task to give up. `AbortSignal.timeout(ms)` makes one that fires after `ms` milliseconds, so a slow service can't leave your code waiting forever.
- AggregateError
- A built-in error that holds an array of other errors in its `errors` property. It lets you report every problem with a form at once, and `Promise.any` uses it when every promise rejects.
- Array.isArray
- A built-in function that returns `true` only when a value is a real array, and `false` for anything else, including objects and strings. It is used to confirm that data loaded from JSON holds a list before looping over it.
- async function
- A function marked `async` always returns a promise, and inside it `await` pauses just that function until a promise settles. If the promise rejects, `await` throws the reason, so ordinary `try`/`catch` handles asynchronous errors.
- async generator
- A generator written `async function*` that can `await` inside. You loop over it with `for await...of`, which awaits each value, such as pages of orders fetched one at a time.
- Asynchronous / synchronous
- Synchronous code runs line by line, each line finishing before the next starts. Asynchronous code, such as waiting for a database or a file, is started and the program carries on, handling the result when it arrives.
B
- bind
- A method that returns a new function whose `this` is always the object you give it. `cart.total.bind(cart)` fixes the lost-`this` problem when a method is passed as a callback.
- Block scope
- A `let` or `const` declared inside a block, the code between a pair of braces, exists only inside that block. This applies to `if` statements and loop bodies.
C
- Callback
- A function you hand to other code to call later, such as the function passed to `setTimeout`. Methods passed this way lose their `this`.
- cause
- An option passed as the second argument to an error's constructor to keep the original error when you wrap it in a higher-level one. It's read later from `error.cause`.
- Cents (storing money in)
- Keeping prices as whole-number cents, such as `1800` for $18, because decimals don't add exactly in JavaScript (`0.1 + 0.2` gives `0.30000000000000004`). You divide by 100 only when you format for display.
- Class
- A blueprint for making objects with the same properties and methods. Each object made from it with `new`, such as a `Product` for the speckled mug, is an instance.
- Closure
- A function together with the variables from the scope where it was written, which it keeps access to even after the outer function has finished. Each call to `makeCounter` makes its own private `count`.
- CommonJS
- Node's older module system, which loads code with `require("name")` and shares it by assigning to `module.exports`. It's still found in many packages and tutorials.
- Constructor
- The special `constructor` method of a class, which runs when you write `new` and sets up the new instance's properties through `this`.
D
- Date
- A built-in object holding one moment, stored as the number of milliseconds since midnight UTC on January 1, 1970. Months count from 0, and methods like `setDate` change the object in place, so copy it first.
- Deep copy
- A copy of every level of nested data, made with the built-in `structuredClone`. Changing the copy never affects the original, though functions can't be copied and class instances come back as plain objects.
- Default import
- An import that gives a module's single main value without braces. An ES module importing a CommonJS file this way receives the whole `module.exports`.
- Dependency injection
- Passing in what a function needs, such as the email sender, instead of importing it inside. That lets a test hand in a fake sender so no real emails go out.
- Destructuring
- Unpacking values from an object (by name) or an array (by position) into separate variables in one line. You can rename, give defaults, reach into nested objects, and do it in parameter lists.
- Dev dependency
- A package needed only while developing, such as the test runner Vitest. It's installed with `npm install -D name`.
- Dynamic import
- `await import(path)` loads a module while the program runs, only when needed, and returns a promise for its exports. It works in CommonJS files too.
E
- ENOENT
- The error code Node gives when a file doesn't exist ("no such file or directory"). Reading `error.code` lets code treat a missing file on the first run as normal.
- Error classes (custom)
- An ordinary class that extends `Error`, with `name` set so logs show the right type, plus extra properties a caller can use, like `available` on `OutOfStockError`. The built-in types cover wrong type, out-of-range numbers, unreadable code or JSON, and unknown names.
- ES modules
- The standard module system, using `import` and `export`. Setting `"type": "module"` in `package.json` makes Node treat your `.js` files this way.
- ESLint
- A tool, installed with `npm install -D eslint`, that reports likely mistakes in your code.
- Event loop
- The part of Node and browsers that decides what runs next. Once the current code finishes, it runs queued callbacks such as timers, after emptying the microtask queue.
- extends / super
- `extends` builds a child class on a parent, inheriting its methods. In the child, `super(...)` runs the parent's constructor and must come before any `this`, and `super.name()` calls the parent's version of a method.
F
- Factory function
- A function that builds and returns another function, like `makeCounter` or `makeLimiter`. Each returned function carries its own private settings through a closure.
- Fake timers
- A Vitest feature that replaces the real clock and timers so tests get predictable results. You set "now" with `vi.setSystemTime` and can skip ahead with `vi.advanceTimersByTime`.
- Falsy
- Values that count as false in a condition, including `0`, `""`, `false`, `null` and `undefined`. `||` replaces all of them with a default, which is why `??` is usually better for defaults.
G
- Generator
- A `function*` that uses `yield` to hand out one value at a time and pause. Calling it returns an iterator and runs no code until `next()` is called, so it can be lazy or describe an endless sequence.
- Getter / setter
- A getter (`get`) is read like a property without parentheses, and a setter (`set`) runs when you assign to a property. A setter is a good place to reject bad values.
- Guard clause
- An early check at the top of a function that throws or returns as soon as input is wrong, so the code below can assume good data. It belongs where data enters the program.
H
- Hoisting
- Function declarations (`function name() {}`) are moved to the top of their scope before the code runs, so you can call them above the line where they're written.
I
- IANA time zone
- A standard zone name such as `America/Los_Angeles`, which you give to `Intl.DateTimeFormat` to show a moment on Portland's or Chicago's clock. Names like `Pacific` are invalid.
- Instance
- An object made from a class with `new`. Every instance of `Product` shares the same methods but has its own property values.
- instanceof
- An operator that checks whether an object was made from a class or from a class that extends it. Callers use it to tell your custom error apart from all others.
- Intl
- A built-in object of formatters that know the conventions of each language and region. It formats money, numbers, dates in a time zone, relative times, plurals and lists such as "coffee, mugs, and notebooks".
- ISO 8601
- The international date format `YYYY-MM-DDTHH:MM:SS`, such as `2026-10-21T16:30:00Z`, where `Z` means UTC. It's the format to store and send, and `toISOString()` produces it.
- Iterable
- A value that `for...of`, spread and destructuring can loop over, because it has a `Symbol.iterator` method that provides an iterator. Arrays, strings, maps, sets and generators are iterable.
- Iterator
- An object whose `next()` method returns `{ value, done }`, handing out items one at a time until `done` is `true`.
J
- JSON
- A text format for data that looks like JavaScript objects but is stricter: double-quoted keys, no comments, and only strings, numbers, booleans, `null`, arrays and objects. `JSON.stringify` writes it and `JSON.parse` reads it.
L
- Lazy evaluation
- Doing work only for the values someone actually asks for. A generator is lazy, so chained generators never copy the whole list.
- Locale
- A code such as `"en-US"` (English, United States) that tells an `Intl` formatter which language and region's conventions to use.
M
- Map / Set
- A Map is a lookup table whose keys can be any value, remembering insertion order and its own size. A Set holds unique values and quickly answers "is this in here?" with `has`.
- Matcher
- A Vitest method such as `toBe`, `toEqual`, `toContain` or `toThrow` that checks a value wrapped by `expect(...)`. If the check fails, the test fails.
- Method
- A function stored in an object or class. Inside it, `this` means the object it was called on.
- Method chaining
- Calling methods one after another on the same object, which works when each method returns `this`, as `card.topUp(25).topUp(15)` does.
- Microtask queue
- The queue where promise callbacks wait. The event loop empties it completely before running the next timer callback, so a `.then` on a settled promise runs before an earlier `setTimeout(fn, 0)`.
- Mock function
- A fake function made with `vi.fn()` that records every call so a test can check how it was used. It can also be told to return or reject a chosen value.
N
- nanoid
- A popular npm package for generating random, short, hard-to-guess unique IDs. Its `customAlphabet` factory returns a function that makes IDs from your own characters and length, such as Kettle & Crane member IDs.
- Node.js
- A program that runs JavaScript outside a web browser, such as on a server or in a terminal. It is best installed as the LTS (long-term support) version, and current examples need Node.js 22.12 or later.
- node:fs
- Node's built-in file system module. The `Sync` versions make the program wait for the disk, while `node:fs/promises` gives promise versions that don't block other work.
- node_modules
- The folder where npm downloads installed packages. It can always be rebuilt, so it's kept out of Git with a `.gitignore` file.
- Non-mutating array methods
- `toSorted`, `toReversed` and `with(index, value)` return a new array and leave the original alone, unlike `sort` and `reverse`, which change it in place. `flatMap` maps each item to an array and joins the results.
- npm
- The command-line tool that comes with Node and downloads packages from the npm registry into your project and tracks them.
- npm commands
- Common npm commands. `npm install` adds packages, `npm audit` checks them against known security problems, `npm outdated` and `npm update` show and apply newer versions, and `npm publish` shares your own library.
- npm scripts
- The `scripts` section of `package.json`, which names project commands. You run one with `npm run name`, and `start` and `test` have shortcuts.
- npx
- A command that runs a package's tool, downloading it first if needed, without adding it to your project, as in `npx prettier --write src/`.
O
- Object.entries / Object.fromEntries
- `Object.entries(obj)` turns an object into an array of `[key, value]` pairs, and `Object.fromEntries(pairs)` turns pairs (or a Map) back into a plain object.
P
- Package
- Reusable code in a folder with a `package.json` describing it, installed from the npm registry. `package-lock.json` records the exact version of everything installed, so teammates and servers get identical code.
- Prettier
- A popular code formatter, run here with `npx prettier --write src/` to tidy every file in `src/`.
- Private field
- A `#name` property that only code inside the class can use. Using it from outside is a syntax error before the program even runs.
- Promise
- An object standing for a result that isn't ready yet: pending, then fulfilled with a value or rejected with a reason. `.then` chains steps, `.catch` handles failures and `.finally` runs either way.
- Promise.all / allSettled / race / any
- Helpers for running promises together. `all` gives every value and rejects if any rejects, `allSettled` reports each outcome and never rejects, `race` follows the first to settle, and `any` follows the first to fulfill.
- Property
- A named value stored on an object, such as `name` or `price`.
R
- Re-export
- A line such as `export { LoyaltyAccount } from "./account.js";` that imports a name and exports it again, so a library's `index.js` can be one entry point.
- Re-throw
- Throwing a caught error again when you can't handle it, so it reaches code that can or stops the program loudly. It keeps a bug from hiding behind a friendly message.
- Regular expression
- A pattern for matching text. `/^\d{5}$/` means start, exactly five digits, end, and its `test` method says whether a string matches.
- Rest / spread
- Three dots mean rest when they collect leftover values into one variable (on the left of `=` or in a parameter list), and spread when they lay items out into a new array, object or call. With spread objects, later properties win.
- Result object
- A return value such as `{ ok: false, error: "Unknown code" }` used instead of throwing, for failures that are a normal answer. The caller checks `ok` every time.
- Reviver / replacer
- A reviver is a function passed to `JSON.parse` that can change each value, for example turning date strings back into `Date`s. A replacer is passed to `JSON.stringify`, and an array of keys keeps only those keys.
S
- Scope
- The part of the code where a name can be seen: module, function or block. Code looks outward through the scope chain, and an inner name that matches an outer one hides it (shadowing).
- Semantic versioning
- Version numbers written MAJOR.MINOR.PATCH, where PATCH is bug fixes, MINOR is non-breaking features and MAJOR can break your code. `^6.0.2` allows any later 6.x.x but never 7.
- setTimeout
- A function that runs a callback after a delay in milliseconds. It returns at once, and the callback runs later through the event loop.
- Shallow copy
- A copy of only the outer object or array; anything nested inside is shared with the original. Spread makes shallow copies.
- Static method
- A method marked `static` that is called on the class itself rather than on instances, such as `GiftCard.fromCode(...)`. It's often used for alternative ways to create an instance.
- Symbol
- A unique value used as a property key that never clashes with ordinary string keys. `Symbol.iterator` is the built-in key that makes an object iterable.
T
- Temporal
- A newer built-in API designed to replace `Date`, with separate types for dates, times, moments and time zones and no 0-based months. As of October 2026 it isn't in Safari or in Node.js 22 or 24 by default.
- Temporal dead zone
- The part of a block before a `let` or `const` line has run, where using the name is an error. You get `ReferenceError: Cannot access 'x' before initialization`.
- Test double
- A stand-in that replaces a risky part, such as the email sender or the clock, during a test. Mock functions and fake timers are examples.
- Test runner
- A tool that finds all your tests, runs them in seconds and reports what failed. An automatic test is code that runs your code with known input and checks the result.
- this
- Inside a method, the object the method was called on (the one before the dot). It's decided at call time, so a method pulled off its object loses it, and arrow functions use the `this` of the surrounding code.
- Thread
- A single line of execution. JavaScript runs one thing at a time on one thread, but avoids waiting by handing slow jobs such as timers to Node.
- toJSON
- A method a class can define to control its own JSON. `JSON.stringify` calls it and uses whatever it returns, which is how `LoyaltyAccount` saves its private history.
- Top-level await
- Using `await` directly at the top of a module file, outside any function. It works in ES modules, such as with `"type": "module"`.
- typeof
- An operator that gives a value's type as a string. It's the one safe way to ask about a name that may not exist.
U
- Unhandled rejection
- A rejected promise that nothing catches. Node stops the whole program and prints the error.
- UTC
- The world's reference time, with no time zone offset and no daylight saving. A good rule is to store and calculate times in UTC, and convert to a local time zone only when showing a time to a person.
V
- var
- The old way to declare a variable. It ignores blocks, belongs to the whole function and is `undefined` before its line; never use it in new code.
- Vitest
- A fast, popular JavaScript test runner. `vitest run` runs every test once, while plain `npx vitest` stays in watch mode, re-running affected tests whenever you save.