number of arguments in nodejs 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 x number of parameters
function display_numbers(...numbers) {
colors.forEach(function(x) {
console.log(x);
});
}
// call it like:
display_numbers(1)
display_numbers(1, 2, 3, 4)
display_numbers(1, -1, 9, 0, 2)