Using Rest Parameters in Javascript


Rest parameters allow functions to accept an indefinite number of arguments as an array.

Source Code

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