DEV Community

Cover image for Spread vs Rest Operators in JavaScript

Spread vs Rest Operators in JavaScript

Barbara Robles (english prof.) on March 12, 2024

Content: Definition Spread Operator Concatenating Arrays Merging Objects Copying Arrays and Objects Turning Strings into Arrays Rest Oper...
Collapse
 
smart_egg profile image
Dmitriy A.

Spreading plain single-dimension arrays into array is the great and undervalued way to clone the Array!

Collapse
 
jangelodev profile image
João Angelo

Hi Barbara Robles,
Your tips are very useful
Thanks for sharing

Collapse
 
faisalkhan4k profile image
Mohammed Faisal Khan

...rest is left
right is ...spread

This would definitely help me!
Thanks a lot

Collapse
 
vaddijaswant profile image
Jaswant Vaddi

This post is of great help, thanks a lot

Collapse
 
sh20raj profile image
Sh Raj

There's some mistake in the third code block 😕

Collapse
 
baroblesvi profile image
Barbara Robles (english prof.)

You mean the changes made in the const a variable, right? Changed it! Thank you for pointing that out!

Collapse
 
stevem profile image
steve

It was a good detailed article. One query, the rest is on the left side of = by left side do you mean when we declare functions or destructure variables?

Collapse
 
baroblesvi profile image
Barbara Robles (english prof.)

Thank you for your comment! Actually, I meant for destructuring! When it comes to functions, the rest is used on function definitions, while the spread operator is used when calling the function! Hope this helps!

Collapse
 
hasibrashid profile image
Hasib Al Rashid

It post made me learn alot! Thanks! 👑

Collapse
 
devsk001 profile image
Dev Sk

....Nice explanation thank you = Thank you

Collapse
 
starswan profile image
Stephen Dicks

Does anyone else struggle with this syntax? A 'concise and clean language' seems a strange phrase for JavaScript - I find this extremely hard to read. I also think that functions with varadic arguments (the rest syntax) should mostly be avoided in application code (which is what the vast majority of us are writing)