Skip to content

JavaScript Basics

Glossary

147 terms from JavaScript Basics, in plain words, each with the chapter that teaches it.

A

Accumulator
The running result that `reduce` carries from one element to the next, such as the growing stock total in `products.reduce((sum, p) => sum + p.stock, 0)`.
Argument
A value you pass to a function when you call it, such as `"Priya"` in `greet("Priya")`.
Array
An ordered list of values in one variable, written in square brackets, like Kettle & Crane's cart `["House Espresso 12 oz", "Speckled mug"]`.
Arrow function
A shorter way to write a function using `=>`, such as `(cents) => cents / 100`. With a single expression after the arrow, the value is returned automatically.
async/await
A JavaScript syntax for writing code that waits for slow jobs, such as downloading data or reading a large file, so that it reads almost like ordinary top-to-bottom code. It is built on promises.

B

Block
A group of statements inside curly braces, such as the code run by an `if` or a loop. Variables declared inside a block exist only there.
Body
The block of code in braces inside a function, which runs each time the function is called.
Boolean
A type with only two values, `true` and `false`, used for yes-or-no answers such as whether an item is in stock. Comparisons give booleans.
Bracket notation
Reading a property by putting its key as a string or variable in square brackets, like `mug["priceCents"]` or `rates[carrier]`. It's needed when the key is in a variable or isn't a valid name.
break
A keyword that leaves a loop or a `switch` case immediately. In a `switch`, forgetting it makes the code run on into the next case.
Breakpoint
A line where the debugger pauses your program so you can look at every variable.

C

Call
To run a function by writing its name followed by parentheses, such as `greet("Priya")`.
Callback
A function passed to another function, which calls it later. Examples are the function given to `map`, to `setTimeout` or to `addEventListener`.
camelCase
A way of writing multi-word names with the first word lowercase and later words capitalized, like `bagWeightLb`.
Case-sensitive
Treating capital and small letters as different, so `price` and `Price` are two separate variables.
catch
The part of `try { ... } catch (error) { ... }` that runs if something in the `try` block throws, letting the program carry on instead of stopping.
Class
A JavaScript feature for making many objects that share the same methods. It acts as a template for creating objects of one kind.
Closure
A function together with the variables around it that it remembers from where it was created.
Code editor
A text editor made for writing code. It colors your code and underlines some mistakes as you type, like VS Code.
Comment
A note for humans after `//`, or between `/*` and `*/`, which JavaScript ignores.
Compare function
A callback given to `sort` that takes two elements, `a` and `b`, and returns a negative number, positive number or 0 to say which comes first, such as `(a, b) => a - b`.
Concatenation
Joining strings together with `+`, such as `"Bloom" + " " + "Café"`.
Conditional operator
A one-line choice, `condition ? a : b`, which gives `a` when the condition is truthy and `b` otherwise, like choosing `"bag"` or `"bags"`.
Console
The place where `console.log` output appears: the browser's developer tools or your terminal. In the browser it also lets you type JavaScript and see results at once.
console.table
A function that prints an array of objects as a table, which is easier to scan than plain `console.log` output when debugging.
const
A keyword that declares a variable whose name can't be pointed at a new value after it is set. It is the usual default for variables, with `let` used only when a value must change.
continue
A keyword that skips the rest of the current loop iteration and jumps to the next one, like skipping canceled order 103.
CORS
A browser safety rule (Cross-Origin Resource Sharing) that restricts what a page can load from another origin. It blocks a page opened straight from disk from loading JavaScript modules, so the page must be served from a local web server instead.
CSV
A plain-text format for spreadsheet data in which the values on each line are separated by commas, like `1042,Bloom Café,8,55`.

D

Debugger
A tool that pauses a program so you can look at its variables and step through it line by line.
debugger (statement)
A statement you write in your code that pauses the program at that point whenever developer tools are open.
Debugging
Finding and fixing the cause of a bug, for example by printing values, using `console.table` or stepping with a breakpoint.
Declare
To create a variable with `const` or `let`, such as `let stock = 40;`.
default
The `switch` case that runs when no other case matches, like "Ask Alex" for an unknown carrier.
Default parameter
A value a parameter takes when no argument is passed, as in `function withTax(cents, rate = 0)`.
delete
An operator that removes a property from an object, such as `delete notebook.pages`.
Destructuring
Unpacking an array or object into separate variables in one step, such as `const [sku, bags] = entry` or `const { sku, qty } = item`.
Developer tools
The browser's panels for looking inside a page, including the console, the Sources debugger and error traces.
document.querySelector
A browser function that finds an element on the page using a selector such as `"#message"`, so a script can read or change it.
DOM
The Document Object Model: the browser's model of a web page as a tree of objects. It lets JavaScript change page elements, respond to clicks and read or update the page's content.

E

ES modules
JavaScript's standard module system that uses `import` and `export`. It works in both Node and browsers, unlike the older `require` system.
Escape
A backslash sequence inside a string that stands for a special character, such as `\"` for a quote mark or `\n` for a new line.
Event
Something that happens on a page, such as a click, a key press or a change to a box. `addEventListener` gives the browser a callback to run when it happens.
Exception
An error raised while a program runs, also called a runtime error. It stops the program unless something catches it.
export
A keyword placed before a value or function in a module to make it available to other files.
Expression
Any code that produces a value, such as a variable or `bags * price`. You can put one inside `${...}` in a template literal.

F

Falsy
A value that counts as false in a condition: `false`, `0`, `""`, `null`, `undefined` and `NaN`.
filter
An array method that keeps only the elements for which your callback returns a truthy value, giving a new array.
finally
A block added after `try`/`catch` for code that must run whether or not an error was thrown.
find / findIndex
Array methods that return the first element passing your test (or `undefined`), or for `findIndex` its position (or `-1`).
for loop
A loop that puts the start, condition and step of counting on one line, like `for (let bags = 1; bags <= 3; bags++)`.
for...of
A loop that runs once for each item in something that holds several, such as each character of a string or each element of an array.
forEach
An array method that calls your function once for each element, without building a result.
Function
A named piece of code that does a job when you call it, like `lineTotal` or `greet`. It can take inputs and give back a result.
Function declaration
Creating a function with `function name(...) { ... }`. Declarations are set up before the file's code runs, so they can be called from anywhere in the file.

G

Global
A variable declared at the top level of a file, outside every block, so any function in the file can read it. Globals are best kept for fixed settings such as `FREE_SHIPPING_CENTS`.

H

HTML
The tag language web pages are written in, such as `<h1>` for a heading and `<p>` for a paragraph.

I

if / else if / else
Statements that run a block only when a condition is true. Conditions are checked in order, and only the first matching block runs.
import
A keyword that brings in names exported by another module, such as `import { money } from "./money.js";`.
in operator
An operator that checks whether a key exists in an object, such as `"pages" in notebook`.
includes / indexOf
Methods on strings and arrays: `includes(x)` answers `true` or `false`, and `indexOf(x)` gives the position or `-1` if it isn't there.
Index
A position in a string or array, counting from 0, so `cart[0]` is the first element.
Infinite loop
A loop whose condition never becomes false, so the program never ends. Press Ctrl+C in the terminal to stop it.
Iteration
One pass through a loop's block.

J

JavaScript
The programming language that every web browser runs, and that Node.js can also run on your own computer or on a server.
JSON
A text format for data, written like JavaScript objects and arrays, that websites and apps use to exchange data. `JSON.stringify` turns a value into JSON text and `JSON.parse` turns it back; keys and strings must use double quotes.

K

Key
The name part of an object's property, such as `priceCents` in `{ priceCents: 1800 }`.
Keyword
A word reserved by the language, such as `let`, `if` or `function`, that can't be used as a variable name.

L

Length
The number of characters in a string or elements in an array, read with `.length`.
let
A keyword that declares a variable whose value can be changed later by assigning to it, without writing `let` again.
Live Preview
A VS Code extension by Microsoft that runs a small local web server, so a page using modules can be opened without a CORS error.
localeCompare
A string method that returns a negative number, 0 or a positive number, as `sort` expects, and handles capitals and accents sensibly. It's used to sort objects by a text property.
Logic error
A bug that gives a wrong answer with no error message at all. You find it by checking results against answers you know.
Logical operators
Operators that combine booleans: `&&` (and) is true when both sides are, `||` (or) when at least one is, and `!` (not) flips true and false.
Lookup table
An object keyed by a code, such as a SKU or carrier, so you can find a value with `table[key]` instead of a long `switch` or `if` chain.
Loop
Code that repeats, such as `while`, `for` and `for...of`.
LTS
Long-term support: a Node.js release line that receives fixes for the longest time, about two and a half years. It is the version most people should install.

M

map
An array method that calls your function on each element and collects the results into a new array of the same length.
Math
A built-in collection of math functions, such as `Math.round` to round to a whole number and `Math.max` to find the biggest.
MDN Web Docs
The standard online reference for JavaScript and the web, at developer.mozilla.org.
Method
A function that belongs to a value and is called with a dot, such as `name.trim()` or `cart.push(x)`.
Module
A file of JavaScript that shares chosen pieces with other files using `export`, which other files bring in with `import`. Anything not exported stays private.

N

NaN
"Not a number": the result of a failed number conversion such as `Number("12 oz")`. It spreads silently through arithmetic, so test with `Number.isNaN`.
new
A keyword that creates a fresh value of a built-in kind, such as `new Date()` or `new Error("message")`.
Node.js
A free program that runs JavaScript on your own computer or on a server, outside the browser.
node:fs
One of Node's built-in modules, whose names start with `node:`. Its `readFileSync` function reads a whole file as a string and makes the program wait until reading is done.
npm
The tool that comes with Node for installing packages other people have written and for creating `package.json` with `npm init -y`.
Nullish coalescing
The `??` operator, which gives a default: `a ?? b` is `a` unless `a` is `null` or `undefined`. Unlike `||`, it keeps a real 0.
Number (conversion)
A function that converts a whole string to a number, or gives `NaN` if it can't. Use it on text from forms, files and the command line before doing math.
Number.isNaN / Number.isInteger
Checks that answer `true` or `false`: `Number.isNaN(x)` tests for `NaN`, and `Number.isInteger(x)` is true only for whole numbers. They are used to validate input.

O

Object
A value that stores named properties in curly braces, like Kettle & Crane's mug `{ name: "Speckled blue mug", priceCents: 1800 }`.
Object.keys / Object.values / Object.entries
Functions that give an object's keys, values or `[key, value]` pairs as an array, so you can loop over an object.
Off-by-one error
A bug where a loop or index runs one time too many or too few, often from mixing up `<` and `<=`.
Operator
A symbol or word that works on values, such as `+`, `===` or `typeof`.
Optional chaining
The `?.` operator, which gives `undefined` instead of an error when the value before it is missing, as in `o.customer?.city`.

P

Package.json
A file describing a JavaScript project. With `"type": "module"` it tells Node to treat your `.js` files as ES modules.
padStart / padEnd
String methods that add characters (spaces by default) at the start or end until the string reaches a given length, handy for lining up columns.
Parameter
A name in a function's definition that receives the argument passed when it's called, such as `name` in `function greet(name)`.
parseInt / parseFloat
Functions that read digits from the start of a string and stop at the first character that doesn't fit. `parseInt` keeps only the whole number.
Predicate
A function that answers `true` or `false`, like `(p) => p.stock > 0`, used by `filter`, `find`, `some` and `every`.
process.argv
An array in which Node puts the words typed on the command line. Index 2 is the first word after the script name.
Program
A list of instructions for a computer, written in a language it understands.
Promise
A JavaScript object that stands for the eventual result of work that takes time, such as downloading data. It lets code say what to do once the work succeeds or fails.
Property
A named value in an object, or a value read with a dot such as `.length`.
push / pop / shift / unshift
Array methods that change the array: `push` and `pop` add and remove at the end, `unshift` and `shift` at the start. `pop` and `shift` give back the removed element.

R

reduce
An array method that combines all the elements into one value, such as a total. Its callback gets the accumulator and the current element, and its second argument is the starting value.
Reference
What a variable holds for an array or object: a pointer to where it lives, not a copy. Two names can share one array, so copy with `slice()` before changing it.
Remainder
What's left after dividing, found with `%`. For example, 14 bags in boxes of 5 leaves `14 % 5`, which is 4.
repeat
A string method that gives the string repeated a number of times, such as `"=".repeat(40)` for a line of 40 equals signs.
REPL
Node's interactive `>` prompt, which reads a line, works it out, prints the result and waits for the next. You start it by typing `node` and leave with `.exit`.
Return
To hand a value back from a function to its caller, which also ends the function. A function without `return` gives back `undefined`.
Runtime error
An error that stops a valid program while it runs, such as reading a property of `undefined`. Common types are `ReferenceError`, `TypeError` and `RangeError`.

S

Scope
The part of a program where a variable can be used. A variable declared inside a function or block exists only there.
script tag
An HTML tag that tells the browser to run a JavaScript file, written `<script src="page.js"></script>`. Add `type="module"` when the file uses `import`.
Server
A computer that sends web pages and data to visitors.
setTimeout
A function that runs a callback after a number of milliseconds. It only schedules the callback, so the lines after it run first.
SKU
Stock-keeping unit: a shop's own code for one product, such as `MUG-BL` for Kettle & Crane's speckled blue mug.
slice
A method on strings and arrays that returns a new piece from `start` up to but not including `end`, leaving the original untouched. On an array, `slice()` with no arguments makes a copy.
some / every
Array methods that answer yes or no: `some` asks whether at least one element passes your test, and `every` asks whether they all do.
sort / toSorted
`sort` puts an array in order by changing it, comparing as strings unless you pass a compare function. `toSorted` takes the same function but returns a sorted copy and leaves the original alone.
splice
An array method that removes a number of elements from a start position, changing the array itself, and returns the removed ones. Extra arguments are inserted in their place.
split / join
`split` cuts a string into an array at each separator, and `join` glues an array's elements into one string with a separator between them.
Spread syntax
The `...arr` form that spreads an array out into separate values, as in `Math.max(...totals)`.
Stack trace
The chain of function calls that led to an error, most recent first. Read the error message, then the first `at` line, then its callers.
Statement
One complete instruction in a program, ending with a semicolon.
String
Text in quotes or backticks. The quotes tell JavaScript it's text, not an instruction.
switch
A statement that compares one value against many `case`s and runs the matching one. It's tidier than a long `else if` chain.
Syntax
The rules for how code must be written.
Syntax error
A mistake that makes the code unreadable to JavaScript, such as a missing `)`, so nothing runs.

T

Template literal
A string in backticks that drops in values with `${...}`, such as `${cafe} ordered ${bags} bags`.
Terminal
A window where you type commands, such as the Terminal app on macOS or PowerShell on Windows.
textContent
A property of a page element that holds its text. Setting it changes what the element shows.
this
A keyword that, inside a method, refers to the object the method was called on. Its value depends on how a function is called, which makes its rules tricky.
throw
A statement that raises an error, such as `throw new Error("Bad quantity")`. It ends the function and any caller until a `catch` handles it.
toFixed
A number method that returns a string with an exact number of decimals, such as `(43130 / 100).toFixed(2)` giving `"431.30"`.
trim / toUpperCase / toLowerCase
String methods that return a new string: `trim` removes spaces at both ends, and `toUpperCase` and `toLowerCase` change the case. Strings can't be changed in place.
Truthy
Any value that isn't falsy, so it counts as true in a condition. Even `"0"` and `"false"` are truthy.
Type
The kind of a value, such as number, string, boolean, `undefined` or `null`, which decides what you can do with it.
Type coercion
JavaScript converting a value's type automatically, as when `"5" * 3` turns `"5"` into a number. It can cause surprises, so it is safer to convert values on purpose with functions such as `Number`.
typeof
An operator that tells you a value's type, such as `typeof 55` giving `'number'`.

U

undefined / null
`undefined` means no value has been given yet, and `null` means deliberately empty. Both are falsy and can be replaced with a default using `??`.
UTF-8
The usual way text is stored as bytes, including letters like é. `"utf8"` asks `readFileSync` for text rather than raw bytes.

V

Value
Any piece of data a program works with, such as a number, string or boolean.
var
An older keyword for declaring variables, with confusing scoping rules. Modern code uses `const` or `let` instead.
Variable
A name that holds a value, created with `const` or `let`, such as `stock` holding 40.
VS Code
Visual Studio Code, a free code editor from Microsoft. It is used to write files, run a terminal and debug Node programs.

W

while
A loop that checks its condition, runs the block if it's true, then checks again. It suits jobs where you don't know how many passes are needed.