accept unlimited number of arguments in a javascript function

To accept unlimited number of arguments in a JavaScript function, we do the following:

  sum = (...numbers) => {
   let total = 0;
   for(const number of numbers){
    total += number
     }
    return total;
   }
    console.log(sum(5,4,6,5,5,6,6,6,6,5,54,4,4,223,433,45564,4,44,4,8686,6,6886,6)) //61972

Generate Random Background Color

Author

Leave a Reply

Your email address will not be published. Required fields are marked *