Best ES6 Features in JavaScript(Spread and Rest)

Spread operator

Spread operator helps to expand an array. This is basically if we want to join two arrays we can simply do it by using this syntax(...).

Earlier if we want to access elements from an array to another array. We used to do this way.

image.png With Spread Operator it is easy to expand or combine arrays with the simple syntax.

image.png

There is also another use-case with Spread Operator just like De-structuring we can also unpack elements from an array.

image.png

Rest Operator

Rest pattern syntax looks like Spread Operator but it does the opposite of what spread operator do. Spread operator helps in unpacking elements from an array. On the other hand, Rest pattern helps to pack elements into an array.

Spread Operator is always used on the right hand side of assignment operator"(=)".

image.png

Rest Operator is always used on the left hand side of assignment operator"(=)".

image.png

image.png