Back to articles
Spread vs Rest Operators in JavaScript

Spread vs Rest Operators in JavaScript

via Dev.to JavaScriptAnoop Rajoriya

Spread and Rest both operators are used same three dots ( ... ) But the difference is how it work? the are opposite in working to each other. Spread is expend the collections and in other hand rest collect those items. In this article we learn about both, what its syntax and how you can use it with arrya or object. Seeing some real world usecases. What spread operator does Spread operator is used to getting out all items form existing collections like arrays or objects. Its always used right side of the assignment operator ( variable = ...something ) and many times you seeing its use with function call ( fn(...something) ) pass all items to function infividually. Think it like you passing entire container of items to some one and in the middle a guy picking all items one by one and giveing it to intended person. What rest operator does Rest operator collect each individual item and wrap it into container which will passing to you. You seeing it's use with functions declaration as a par

Continue reading on Dev.to JavaScript

Opens in a new tab

Read Full Article
2 views

Related Articles