ES6: Rest/Spread operator

According to MDN,The rest parameter syntax allows us to represent an indefinite number of arguments as an array”.

It is useful because it will collect all of the arguments excluding the first given in a particular parameter. For example, (taken from MDN)

function multiply(multiplier, ...theArgs) {
return {
return multiplier * element;

var arr = multiply(2, 1, 2, 3);
console.log(arr); // [2, 4, 6]

This is useful because now we don’t have to do the following to achieve the same result:

function multiply(multiplier){
  var args =, arguments.length);
// of code

Another example:

function sortRestArgs(...theArgs) {
var sortedArgs = theArgs.sort();
return sortedArgs;

console.log(sortRestArgs(5, 3, 7, 1)); // shows 1, 3, 5, 7

You couldn’t do this in ES5:

var sortedArgs = arguments.sort(); // <-- wouldn't work

You would have to set the variable using Array.slice:

var args =;
var sortedArgs = args.sort();

Hope this helps!

Note: all examples derived from MDN (←click)

One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.