Two different concepts with the same syntax.
The Rest Parameter
A Rest Parameter is used as the last argument of a function declaration. It is enabling the user to specify any number of parameters.
A function can also have common parameters as long as the Rest Parameter is the last one.
Rest Parameter vs. Arguments
Arguments is an Array-like Object; we cannot directly apply Array-functions to it. We have to make use of the Spread Operator to unfold the Arguments Object in an Array first. For instance: In the last example, we could apply the join method directly to our
The Spread Operator
While syntactically the same, the Rest Parameter and Spread Operator are different concepts. Consider the following example:
If you extend an object like above, the values on the right side will overwrite possible duplicates on the left side. This method can be used in an immutable context.
Despite having the same syntax, the Spread Operator and the Rest Syntax are the opposite of each other. While spread will expand your expression, rest will cast a list of values into an Array.
That’s all, folks!
Thank you for reading.