What is the difference between spread and rest operator in JavaScript | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

What is the difference between spread and rest operator in JavaScript

29th Jul 2020, 8:19 AM
paperinflames
paperinflames - avatar
2 Answers
+ 3
In short, REST collects all the remaining elements into an array whileSpread operator allows arrays/objects/strings to be expanded into single arguments/elements. https://www.google.com/url?sa=t&source=web&rct=j&url=https://codesquery.com/javascript-rest-vs-spread/%3Famp&ved=2ahUKEwiC9-Wth_LqAhVvzDgGHQQCAk4QFjABegQIEhAH&usg=AOvVaw0lik5lJAZqihMUblwGYC06&ampcf=1
29th Jul 2020, 8:38 AM
123
+ 1
rest operator is passed in argument of a function to accept arguments as many as you want. spread operator is used to copy arrays and objects.https://code.sololearn.com/WsQ0aJJuN0k5/?ref=app
29th Jul 2020, 10:26 AM
🇮🇳Vivek🇮🇳
🇮🇳Vivek🇮🇳 - avatar