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.

Code Example
PREVIEW READY
Loading Editor...
Live Preview

2️⃣ Spread Operator with Arrays

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

Code Example
PREVIEW READY
Loading Editor...
Live Preview

3️⃣ Spread Operator with Objects

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

Code Example
PREVIEW READY
Loading Editor...
Live Preview

4️⃣ Shallow Copy Limitation

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

Code Example
PREVIEW READY
Loading Editor...
Live Preview

🧠 Test Your Knowledge

3 Questions

Progress: 0 / 3
Keep Going!AJS - Modules