JavaScript

Spread, Rest & Destructuring

Master modern JavaScript syntax! Learn spread operator, rest parameters, and destructuring for cleaner, more efficient code.

By TechCoder TeamLast updated: 2026-06-02
In a Nutshell

Master modern JavaScript syntax! Learn spread operator, rest parameters, and destructuring for cleaner, more efficient code. This hands-on tutorial focuses on practical implementation of spread, rest & destructuring concepts.

Spread, Rest & Destructuring

ES6 introduced powerful features that make working with arrays and objects much cleaner. Once you learn these, you'll wonder how you lived without them!

1. The Spread Operator (...) 📤

What is it? It "spreads" or expands an iterable (like an array or string) into individual elements.

Why use it? To copy arrays, combine them, or pass elements as arguments without using loops or concat().

How it works: Think of it as taking the items out of the box.

JAVASCRIPT PLAYGROUND
⏳ Loading editor…

2. The Rest Parameter (...) 📥

What is it? It looks exactly like Spread, but it does the opposite. It "collects" multiple elements into a single array.

Why use it? To handle an unknown number of function arguments.

How it works: Think of it as putting items into a box.

JAVASCRIPT PLAYGROUND
⏳ Loading editor…

3. Destructuring 📦

What is it? A syntax to "unpack" values from arrays or properties from objects into distinct variables.

Why use it? It's much cleaner than accessing items one by one (e.g., arr[0], obj.name).

Array Destructuring

Order matters!

JAVASCRIPT PLAYGROUND
⏳ Loading editor…

Object Destructuring

Names matter! (Order doesn't).

JAVASCRIPT PLAYGROUND
⏳ Loading editor…

Practical Example: Config Merger ⚙️

JAVASCRIPT PLAYGROUND
⏳ Loading editor…

AI Mentor

Confused about "JavaScript spread operator, rest parameters, and destructuring"? Ask our AI mentor for a simplified explanation.

Quiz

Quiz

Question 1 of 4

What does the Spread operator (...) do?

Collects items into an array
Expands an array into individual elements
Deletes elements
Sorts the array

Key Takeaways

Spread (...): Expands arrays/objects (Unpack).
Rest (...): Collects arguments (Pack).
Destructuring: Extracts values into variables.
Object Destructuring: Uses {} and property names.
Array Destructuring: Uses [] and order.

What's Next?

Now that you've mastered modern syntax, let's dive deeper into Objects & Nested Objects!

Keep coding! 🚀