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


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, th

Source: DEV Community

December 1, 2021
Category : News
Tags: beginners | javascript | productivity | webdev

Leave a Reply

Your email address will not be published. Required fields are marked *

Sitemap | Terms | Privacy | Cookies | Advertising

Senior Software Developer

Creator of @LzoMedia I am a backend software developer based in London who likes beautiful code and has an adherence to standards & love's open-source.