Menu

1 / 2

Spread vs Rest Operators in JavaScript

DEV Community·Pratham·6 months ago
#1MEgQI96
#spread#rest#part#copying#const
Reading 0:00
15s threshold

Same three dots, two completely different jobs.

JavaScript has this funny thing where the exact same syntax — ... (three dots) — does two opposite things depending on where you use it. In one context, it spreads values out. In another, it collects values together.

When I first encountered this in the ChaiCode Web Dev Cohort 2026, I kept mixing them up. "Wait, is ... expanding or gathering here?" It took a few examples before the distinction clicked. And once it did, I started seeing both operators everywhere — in function parameters, array manipulation, object merging, you name it.

Let me break it down the way I wish someone had explained it to me.

The Core Idea: Expanding vs Collecting

Before we look at any syntax, understand this one concept:

Spread = expanding a collection into individual pieces

Rest = collecting individual pieces into a collection

That's the entire difference.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.