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

Recent Posts

Essential VS Code Extensions Every Developer Should Use

Visual Studio Code (VS Code) is powerful out of the box, but its real strength…

3 days ago

JavaScript Variables

1. What Is a Variable in JavaScript? A variable is a named container used to store data…

4 days ago

C++ Queue

1. What Is a Queue? A Queue is a linear data structure that follows the principle: FIFO – First…

5 days ago

Must-Know Angular Concepts

Angular is a full-featured frontend framework built by Google for creating large, maintainable, and high-performance web applications.…

6 days ago

Responsive Web Design (RWD)

What Is Responsive Web Design? Responsive Web Design (RWD) is an approach to building websites…

7 days ago

Geolocation API in JavaScript

The Geolocation API allows a web application to access a user’s geographical location (latitude, longitude, and more), with…

2 weeks ago