Rest and Spread operator
Rest and the
Spread parameters are still very unclear to some people, and it seems to have so many people confused because they are identical. The
Spread operators are represented with
I still don’t have any idea on why the both of them are represented with
... , honestly I feel like they should have come up with something else. So now let’s dive in to what they are and what they are used for.
If we have a function and we don’t know how many arguments that will be passed in, we use the
In the image above the
... was used to handle what was passed into the function, if more values are passed into the function the
Rest operator will take care of them.
Spread operator can be used in different situations, it can also work with a function. I’ll show you the different scenarios were it can be used.
In the picture above the
Spread operator was used to expand the array so it could be passed into the function.
In this image, the spread operator was used to neutralize an array so an operation could be carried out on each of the values in the array.
Spreadoperator is used to neutralize an array.
Source: DEV CommunityDecember 1, 2021