Search⌘ K

The Spread Operator

Explore how the spread operator in JavaScript simplifies passing array elements as individual function arguments. Understand its difference from rest parameters and how it enhances function calls without needing the apply() function. Gain skills to write cleaner and more versatile JavaScript code by mastering the spread operator.

The spread operator looks the same as the (...) symbol used for the rest parameter. However, it is used when calling a function instead of in the parameter list.

The spread operator’s intention is the opposite of the rest parameter’s—spread breaks a collection into discrete values, whereas rest gathers discrete values into an array.

Since they are used in two different contexts, there should be no confusion.

Difference between the rest parameter and the spread operator

Different ways to pass arguments

Suppose we have a greet() function ...