#the rest paramater converts all of the variables you pass into a function into an array

Base example before the rest paramater

let numbers = [1,2,3,4,5];

function sumUp(toAdd) {
  let result = 0;
  for (let i = 0; i < toAdd.length; i++) {
  result += toAdd[i]
  }
  return result;
}

console.log(sumUp())

1
2
3
4
5
6
7
8
9
10
11
12

Using rest paramaters


function sumUp(...toAdd) {
  console.log(toAdd)
  let result = 0;
  for (let i = 0; i < toAdd.length; i++) {
  result += toAdd[i]
  }
  return result;
}

console.log(sumUp(100, 10, "20"))

1
2
3
4
5
6
7
8
9
10
11
12
Last Updated: 8/11/2019, 10:51:29 PM