Skip to content

Instantly share code, notes, and snippets.

@jpetto
Created August 30, 2012 15:01
Show Gist options
  • Save jpetto/3530246 to your computer and use it in GitHub Desktop.
Save jpetto/3530246 to your computer and use it in GitHub Desktop.
JavaScript functions - arguments example
var add = function() {
var sum = 0;
for (var i = 0; i < arguments.length; i++) {
sum += arguments[i];
}
return sum;
};
console.log(add(2));
console.log(add(2, 3));
console.log(add(2, 3, 5));
console.log(add(6, 'turkey', 3, 5));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment