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

JavaScript Memoization

In JavaScript, it’s commonly used for: Recursive functions (like Fibonacci) Heavy calculations Repeated API/data processing…

4 days ago

CSS Container Queries: Responsive Design That Actually Makes Sense

For years, responsive design has depended almost entirely on media queries. We ask questions like: “If…

4 days ago

Cron Jobs & Task Scheduling

1. What is Task Scheduling? Task scheduling is the process of automatically running commands, scripts,…

4 days ago

Differences Between a Website and a Web App

Here’s a comprehensive, clear differentiation between a Website and a Web App, from purpose all the…

2 weeks ago

Essential VS Code Extensions Every Developer Should Use

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

4 weeks ago

JavaScript Variables

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

4 weeks ago