Javascript - Three point ''...'' - Spread and Rest

> (World Wide) Web - (W3|WWW) > Javascript (Js|ECMAScript) > ECMAScript - Grammar Standard

1 - About

The three points may refer to:

Advertising

3 - Syntax

3.1 - Spread

The spread syntax allows an expression to be expanded in places where multiple arguments (for function calls) or multiple elements (for array literals) or multiple variables (for destructuring assignment) are expected.

Spread syntax can be applied only to iterable objects

  • For function calls:
myFunction(...iterableObj);
  • For array literals:
[...iterableObj, 4, 5, 6];

3.2 - Rest

The rest parameter syntax allows to represent an indefinite number of arguments as an array.

  • For function definition:
function f(a, b, ...theArgs) {
  // ...
}

where:

Advertising
web/javascript/es/spread.txt · Last modified: 2019/02/16 17:40 by gerardnico