Skip to content

Instantly share code, notes, and snippets.

@Ajax30
Created November 12, 2016 07:26
Show Gist options
  • Save Ajax30/d95d77241210e7e0c6a0b2beb47e5682 to your computer and use it in GitHub Desktop.
Save Ajax30/d95d77241210e7e0c6a0b2beb47e5682 to your computer and use it in GitHub Desktop.
Add ALL the arguments passed to a function
function add(){
var sum = 0;
// Use "the arguments object" to add up all the arguments
// passed to a function
for (i=0; i<arguments.length; i++){
var sum = sum + arguments[i];
}
console.log(sum);
}
// You can now add as many numbers as you like
// just by passing them to the function
add(1, 2, 5);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment