Nearby lessons

12 of 22

JavaScript: Spread Operator

📌 What is Spread Operator?

The Spread Operator (...) allows you to expand iterable elements (like arrays or strings) into individual elements. It is also useful for cloning or merging arrays and objects.

1️⃣ Spread Operator with Function Arguments

You can use the spread operator to pass array elements as separate arguments to a function.

Example02
🚀Code Cell
Loading Editor...
✏️ You can edit this code — click Run to refresh the preview.
Output

2️⃣ Spread Operator with Arrays

You can use ... to clone or merge arrays easily.

Example03
🚀Code Cell
Loading Editor...
✏️ You can edit this code — click Run to refresh the preview.
Output

3️⃣ Spread Operator with Objects

Spread operator can also be used to merge or clone objects.

Example04
🚀Code Cell
Loading Editor...
✏️ You can edit this code — click Run to refresh the preview.
Output

4️⃣ Shallow Copy Limitation

Spread operator creates a shallow copy of objects. Nested objects are still referenced.

Example05
🚀Code Cell
Loading Editor...
✏️ You can edit this code — click Run to refresh the preview.
Output

🧠 Test Your Knowledge

3 Questions
Progress: 0 / 3