Spread syntax, often called the spread operator, is the JavaScript notation ... that expands an iterable or an object into its individual parts inside an array literal, a function call or an object literal. In browser JavaScript, it is the standard way to copy, merge and pass collections without mutating the original data, and it appears throughout modern web application code.
Spread syntax was introduced for arrays and function calls in ECMAScript 2015 and extended to object literals in ECMAScript 2018. Strictly speaking it is syntax, not an operator, because ...value cannot stand alone as an expression; it only works in the three contexts the language defines.
How spread syntax expands values
Spread syntax works by iterating the source value and inserting each produced element at the position of the three dots. In array literals and function calls, the engine calls the value’s Symbol.iterator method, so any iterable works: arrays, strings, Map, Set, NodeList and generator results.
In object literals, the mechanism is different: the engine copies the source object’s own enumerable properties, including symbol keys, as if by assignment of each key in turn. Prototype properties and non-enumerable properties are not copied, and accessor definitions are lost: getters are invoked and only their current values are stored. Class instances therefore lose their methods and become plain data objects after spreading.
| Context | Example | What is expanded | Requirement |
|---|---|---|---|
| Array literal | [...a, ...b] | Elements of an iterable | Value must be iterable |
| Function call | Math.max(...nums) | Elements as separate arguments | Value must be iterable |
| Object literal | {...defaults, ...opts} | Own enumerable properties | Any value; null is ignored |
Spreading a plain object into an array, as in [...{a: 1}], throws a TypeError because ordinary objects are not iterable. Spreading null or undefined into an object literal, by contrast, is silently ignored, which is convenient for optional configuration.
Spread syntax compared with rest and older techniques
Spread syntax and rest syntax use the same three dots but do opposite jobs: spread expands one value into many, while rest collects many values into one. The position decides which is meant: rest appears in parameter lists and destructuring patterns, spread in literals and calls.
| Technique | Direction | Typical use | Note |
|---|---|---|---|
| Spread syntax | Many out of one | Copy, merge, pass arguments | Creates new arrays or objects |
| Rest parameters | One out of many | Variable-length function arguments | Must be the last parameter |
| Destructuring assignment with rest | One out of many | Extract some keys, keep the rest | Pairs naturally with spread |
| Object.assign() | Merge into target | Merging objects | Mutates the target and triggers setters |
| Function.prototype.apply() | Array to arguments | Legacy argument passing | Largely replaced by spread |
A subtle difference from Object.assign() is that spread defines new properties on a fresh object instead of assigning them to an existing one, so setters on the target are never called and the result is always a new plain object.
Common patterns in browser code
Spread syntax is most valuable wherever code must produce a new value instead of changing an old one, which is the core rule of state management in many frontend frameworks. The patterns below are the ones that appear most often.
| Pattern | Example | Purpose |
|---|---|---|
| Shallow copy of an array | const copy = [...items] | Avoid mutating shared data |
| Immutable state update | {...state, loading: false} | Change one field in a new object |
| Merging defaults | {...defaults, ...userOptions} | Later keys override earlier ones |
| Converting a NodeList | [...document.querySelectorAll('li')] | Use array methods on DOM results |
| Removing duplicates | [...new Set(tags)] | Unique values in insertion order |
| Conditional property | {...(isAdmin && {role: 'admin'})} | Add a key only when true |
Order matters in object spread: when keys collide, the last occurrence wins. Writing {...userOptions, ...defaults} instead of the reverse is a classic bug that silently discards the user’s settings.
Shallow copies and performance limits
Spread syntax creates only a shallow copy: the top-level container is new, but nested arrays and objects are shared by reference. Modifying copy.user.name therefore also changes the original, which surprises developers who expect a full clone.
For a true deep copy, the browser provides structuredClone(), which handles nested structures, dates, maps and circular references, although it cannot clone functions or DOM nodes. Spread remains the right tool when only the outer level must change.
| Symptom | Cause | Remedy |
|---|---|---|
| Original object changes unexpectedly | Nested data shared by shallow copy | Spread each changed level or use structuredClone() |
| RangeError in a function call | Spreading a very large array as arguments | Use a loop or reduce instead |
| Slow rendering in large lists | Copying big arrays on every update | Batch updates or use mutable structures locally |
| TypeError: not iterable | Spreading a plain object into an array | Use Object.values() or Object.entries() |
Each spread allocates a new array or object and copies every element, so the cost is linear in size. Inside loops this can turn an algorithm from linear to quadratic, for example when an accumulator array is re-spread on every iteration of reduce.
Browser support and transpilation
Array and call spread are supported in all current evergreen browsers, and object spread has been available in them since about 2018. Only projects that still target legacy engines such as Internet Explorer 11 need a build step.
Transpilers such as Babel and TypeScript rewrite spread into helper calls or concat and Object.assign equivalents. The output is functionally close but not identical: loose transpilation modes may skip iterator semantics, which changes results for Set, Map and generator sources.
The short version
Spread syntax is three dots that tell JavaScript to unpack a collection into its separate pieces. Imagine emptying a bag of groceries onto a table: the items are the same, but now each one lies on its own and can be arranged with other items.
Programmers use it to make copies and combine lists or settings without damaging the originals. It is short, easy to read and works in every modern browser, but it only copies the top layer, not the items packed inside.
Where it makes a difference
A front-end developer builds a shopping cart for an online store. Each time a customer changes a quantity, the code creates the next state with {...cart, items: cart.items.map(...)}, replacing only the changed item and keeping every other entry intact. Because the old state is never mutated, the framework detects the change by a simple reference comparison and re-renders only the affected row.
Earlier, the same component used direct mutation, and the quantity badge sometimes failed to update. Switching to spread-based immutable updates removed the stale display bug and made the undo feature trivial: the previous cart object is still available, unchanged, and can be restored with a single assignment.