Categories: softare development

Accept Unlimited Number of Arguments in 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

codeflare

Latest tech news and coding tips.

Share
Published by
codeflare

Recent Posts

Backpressure in Node.js

Backpressure is a flow-control mechanism that prevents a fast data producer from overwhelming a slower data…

2 days ago

JavaScript Collections

JavaScript collections are data structures used to store, organize, retrieve, and manipulate groups of values. Choosing…

2 days ago

Context Poisoning Explained

Context poisoning is a technique where an attacker deliberately places misleading, malicious, or irrelevant information into…

6 days ago

Common React Errors

React makes building user interfaces easier, but certain errors appear repeatedly, especially when working with…

2 weeks ago

C Programming Cheat Sheet

The C programming language is a foundational, general-purpose computer programming language created by Dennis Ritchie at Bell Labs in 1972. Originally developed to…

2 weeks ago

Homebrew Tutorial

What Is Homebrew? Homebrew is a package manager for macOS and Linux that makes it easy to…

3 weeks ago