Skip to main content

Command Palette

Search for a command to run...

Spread vs Rest Operators in JavaScript

Updated
1 min readView as Markdown
Spread vs Rest Operators in JavaScript

Spread and Rest operators both uses triple dot(...) but what's the difference in both Let's Understand it in this blog

Spread Operator

Spread operator means as it's word say spread means expanding , like this also spread operator expands the values,it shows multiple values of array or objects,also it used for creating data

It is used right side of the assignment operator

let nums = ...nums;
OR
let sum = fn(){};
fn(...nums);

It is like getting out the values from a collection, means individuals value comes together and form a collection,it passes individually values to a function

Rest Operator

rest operators are opposite of spread operator it makes a single collection in which all the values are given.

function(...nums){};

It passed in function argument as a single collection of all values

Spread Operator VS Rest Operator

5 views