How do push() and concat() differ in what they return and whether they change the original array?
Show the explanation
Model answer.
- `push(...items)` adds items to the end of the same array (mutates it) and returns the new length.
- `concat(...values)` returns a new array made of the original plus the values; the original is unchanged. Arrays passed to
concatare flattened one level.
const a = [1, 2];
a.push(3); // returns 3; a is [1, 2, 3]
const b = a.concat([4, 5], 6); // b is [1, 2, 3, 4, 5, 6]; a unchanged
a.push([4, 5]); // a is [1, 2, 3, [4, 5]]: push does not flattenA common bug is writing list = list.push(x), which replaces the array with a number. When you need immutability (for example React state), use concat or spread: setItems([...items, x]).
Original UniCircle question. Last reviewed 22 Oct 2026.
