JavaScript Rest Parameters

This Scrimba screencast was created by Dylan C. Israel.

The rest parameteropen in new window is used to represent an infinite number of arguments as an array. The rest parameter syntax is ... preceding the parameter name. This can be effect when the number of arguments is unknown, or required to be grouped together.

NOTE

Only the last parameter can be a "rest parameter"

function add (...numbers) {
  return numbers.reduce(function (total, number) {
    return total += number
  })
}

console.log(add(4, 8, 3, 5, 2)) // 22

See Also

This YouTube video was created by Steve Griffith.