spread syntax
The three-dot JavaScript syntax that copies the items of an array or the properties of an object into a new one.
In more detail
[...list, item] creates a new array with one more item, and { ...obj, name } creates a new object with one field changed. The copy is shallow, so nested objects are still shared.
Examples
React state updates rely on it to create new values instead of changing the old ones.setItems((prev) => [...prev, newItem])Related terms
- immutable — Something that cannot be changed after it is created; to change it you make a new one.
- destructuring — JavaScript syntax that unpacks values from an object or array into separate named variables in one step.
- reference equality — Comparing two references to see whether they point to the very same object, rather than to objects with equal contents.
- rest parameter — A final function parameter written ...args that collects all remaining arguments into an array.
- variadic tuple — A tuple type containing a spread such as [query: string, ...params: (string | number)[]], so its length can vary.
Taught in
- State with useState: Immutability And Asynchronous Batching — React 19 & Modern Component Architecture
- Tuples: Fixed Length, Labeled Elements And Variadic Tuples — Production TypeScript