CKTIS / JavaScript
Destructuring objects and iterables
Destructuring reads object properties or successive iterable values through a pattern. It supports declaring variables, assigning to existing variables, renaming bindings, supplying defaults, and collecting remaining values or properties.
Version: ECMAScript and Web APIs; exact feature edition and browser support reviewed per entry; Node 24 in repository does not prove browser API support
Syntax
const { key: localName = fallback, ...rest } = object;
const [first, , third = fallback, ...tail] = iterable;
({ key: existingVariable } = object);Destructuring (destructuring) is pattern syntax, not a function or keyword. An object pattern { key } reads a property by key, whereas [first] consumes a value from an iterator—the source need not be an array. Patterns can be nested and also used in function parameters.
The declaration const { key: localName = fallback } = object creates localName, not key. A default is evaluated only when the extracted value is undefined, including a missing property; null, 0, and false do not trigger it. Destructuring null or undefined throws TypeError; an array pattern requires an iterable value.
A comma in an array pattern can skip a position. A final ...tail collects remaining iterator values into a new array; ...rest in an object pattern copies remaining own enumerable properties into a new object. Rest must come last, without a trailing comma. This is not deep copying: nested objects remain shared references.
A declaration creates bindings, whereas assignment updates existing targets. When an object assignment starts a statement, use parentheses: ({ key: existingVariable } = object);, so { does not start a block. In the example, userName receives "Ada", and the undefined values trigger defaults.
Examples
const record = { name: "Ada", score: undefined, active: true };
const { name: userName, score = 10, ...rest } = record;
const [first, , third = 9, ...tail] = [2, 4, undefined, 8];
console.log(`${userName}|${score}|${rest.active}|${first}|${third}|${tail.join(",")}`);Result
Ada|10|true|2|9|8
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.