Skip to main content

Command Palette

Search for a command to run...

JavaScript: Sum all the arguments of a function

Updated
1 min read
JavaScript: Sum all the arguments of a function
H

Full stack developer (ReactJS, NodeJS, JavaScript, PHP, SQL)

function getSumOfNumbers (...numbers) { 
  return numbers.reduce((a, b) => a + b, 0);
}

var sumOfNumbers = getSumOfNumbers(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
console.log('sumOfNumbers:', sumOfNumbers);
Output:
sumOfNumbers: 55

Execute above code here

More from this blog

E

Everyday Dev Patterns

26 posts

A collection of real-world JavaScript snippets, patterns, and gotchas from my day-to-day work.