Pratik Jadhav

Apr 27, 2026 • 1 min read

Spread vs Rest Operators in JavaScript

Understanding how to expand and collect data in a clean and modern way

In JavaScript, the spread and rest operators look the same, but they do opposite things depending on how you use them.

At a simple level, spread is used to expand values, while rest is used to collect values.

Think of spread like unpacking items from a bag. If you have a bag of fruits and you open it, all the fruits come out individually. That is what spread does with arrays or objects.

It takes a collection and expands it into individual elements.

This is very useful when you want to copy data, merge arrays, or combine objects without modifying the original ones. Instead of manually looping and adding items, you can quickly expand everything in a clean way.

Now think of rest like packing items into a bag.

If you have multiple items and you want to group them together into one structure, rest helps you collect them. It gathers remaining values into a single variable.

This is often used when working with functions that can take multiple inputs. Instead of handling each value separately, you collect them into one place and work with them easily.

The key difference is direction.

Spread takes something grouped and breaks it into individual pieces.

Rest takes individual pieces and groups them into one structure.

In real world usage, spread is commonly used when copying arrays, merging data, or updating objects without changing the original.

Rest is commonly used when you do not know how many values will come in and you want to handle them in a flexible way.

Even though they use the same syntax, understanding the intent makes everything clear.

If you are expanding data, it is spread.

If you are collecting data, it is rest.

Once this clicks, working with arrays, objects, and function arguments becomes much more simple and expressive in modern JavaScript.

Join Pratik on Peerlist!

Join amazing folks like Pratik and thousands of other builders on Peerlist.

peerlist.io/

It’s available... this username is available! 😃

Claim your username before it's too late!

This username is already taken, you’re a little late.😐

0

0

0