Rest and Spread operator

Hello programmers,

The ES6 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 Rest and Spread operators are represented with … .

I still don’t have any …


This content originally appeared on DEV Community and was authored by Arnold

Hello programmers,

The ES6 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 Rest and 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.

REST OPERATOR

If we have a function and we don't know how many arguments that will be passed in, we use the Rest operator.

Rest operator
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

The 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.

Spread operator example 1
In the picture above the Spread operator was used to expand the array so it could be passed into the function.

spread operator example 2
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.

Basically, the Spread operator is used to neutralize an array.

Alright, this is all I have on the Rest and Spread operator. I hope you guys apply it in your new projects.


This content originally appeared on DEV Community and was authored by Arnold


Print Share Comment Cite Upload Translate Updates
APA

Arnold | Sciencx (2021-12-01T16:12:11+00:00) Rest and Spread operator. Retrieved from https://www.scien.cx/2021/12/01/rest-and-spread-operator/

MLA
" » Rest and Spread operator." Arnold | Sciencx - Wednesday December 1, 2021, https://www.scien.cx/2021/12/01/rest-and-spread-operator/
HARVARD
Arnold | Sciencx Wednesday December 1, 2021 » Rest and Spread operator., viewed ,<https://www.scien.cx/2021/12/01/rest-and-spread-operator/>
VANCOUVER
Arnold | Sciencx - » Rest and Spread operator. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/12/01/rest-and-spread-operator/
CHICAGO
" » Rest and Spread operator." Arnold | Sciencx - Accessed . https://www.scien.cx/2021/12/01/rest-and-spread-operator/
IEEE
" » Rest and Spread operator." Arnold | Sciencx [Online]. Available: https://www.scien.cx/2021/12/01/rest-and-spread-operator/. [Accessed: ]
rf:citation
» Rest and Spread operator | Arnold | Sciencx | https://www.scien.cx/2021/12/01/rest-and-spread-operator/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.