Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Web Technology by (7k points)

Can someone explain to me the difference between spread syntax and rest parameters in ES2015?

1 Answer

0 votes
by (13.1k points)

In a spread, you are expanding a single variable into more

var ijk=[‘i’,’j’,’k’];

var xyz=[‘x’,’y’,’z’];

var a=[...ijk,..xyz];

console.log(a)

The output will be [“i”,”j”,”k”,”x”,”y”,”z”]

In a rest argument, you are collapsing all the arguments of a function into an array

function sum( first, ...others )

 {

 for ( var i = 0; i < others.length; i++ ) 

first += others[i]; 

return first; 

}

 console.log(sum(1,2,3,4))

Want to be a full stack developer? Check out the full stack developer course from Intellipaat.

Related questions

Browse Categories

...