FrontendDeveloper.in

ECMAScript question detail

Spread Operator

Spread Operator allows iterables( arrays / objects / strings ) to be expanded into single arguments/elements.

  1. In function and constructor calls, the spread operator turns iterable values into arguments
console.log(Math.max(...[-10, 30, 10, 20])); //30
console.log(Math.max(-10, ...[-50, 10], 30)); //30
  1. In Array literals and strings, the spread operator turns iterable values into Array elements
console.log([1, ...[2,3], 4, ...[5, 6, 7]]); // 1, 2, 3, 4, 5, 6, 7

Note: The spread syntax is opposite of rest parameter.

Back to all ECMAScript questions
Get LinkedIn Premium at Rs 399