function recognised as variable parameters code example
Example 1: javascript check if argument is passed
function func(arg1, arg2) {
if (typeof arg2 === "undefined") {
arg2 = "defaultValue";
}
//Rest of function
}
Example 2: javascript function variable arguments
function foo() {
for (var i = 0; i < arguments.length; i++) {
console.log(arguments[i]);
}
}
foo(1,2,3);
//1
//2
//3