Using Rest Parameters in Functions in Javascript


Accept an indefinite number of arguments as an array.

Source Code

function sum(...nums) {
  return nums.reduce((acc, cur) => acc + cur, 0);
}
console.log(sum(1, 2, 3)); // 6
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments