You can pass several parameters in your function and access them through the arguments variable. Below is an example of a function that returns the sum of all the parameters that you passed in it.
var sum = function () { var res = 0; for (var i = 0; i < arguments.length; i++) { res += parseInt(arguments[i]); } return res; }
You can call it like this:
sum(1, 2, 3);
source share