Rest and spread are two new operators in the new ES6 (ECMAScript 6) standard which Javascript implements. Javascript development in Drupal 8 Core is now done in ES6. See: https://www.drupal.org/node/2815083
Both Rest and Spread are represented with 3 dots (…).
REST (“the rest of the parameters”) is used in function calls where you want to treat an indefinite number of arguments like an array, like this:
/*
* accept any number of strings
*/
function concat_words(prefix, ...words) {
return prefix + words.join(" ");
}
concat_words("The sentence is: ", "I", "can", "use", "any", "number", "of", "arguments");
// => "The sentence is: I can use any number of arguments"
The rest operator takes however many arguments are “left” at the end of a list of arguments, and puts them in an array.
Examples: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/rest_parameters#Examples
SPREAD is the opposite, and is used where you have an array but want to have a list of elements.
var arr1 = [1, 2, 3];
var arr2 = [4, 5, 6];
// instead of using concat to join two arrays
both = arr1.concat(arr2);
// use this which is easier to visualize
both = [...arr1, ...arr2];
Examples: https://davidwalsh.name/spread-operator
Where does ES6 work? Pretty much any modern browser. Here is a browser compatibility guide.
You can use a transpiler like babel (https://babeljs.io) to generate Javascript for older browsers.