How do I create a function that returns the number of argument/s it was called with.
Examples:
numArgs() ➞ 0
numArgs("foo") ➞ 1
numArgs("foo", "bar") ➞ 2
numArgs(true, false) ➞ 2
numArgs({}) ➞ 1
My code
function numArgs() {
}
How do I create a function that returns the number of argument/s it was called with.
Examples:
numArgs() ➞ 0
numArgs("foo") ➞ 1
numArgs("foo", "bar") ➞ 2
numArgs(true, false) ➞ 2
numArgs({}) ➞ 1
My code
function numArgs() {
}
you can use arguments.length as defined by MDN
function numArgs() {
return arguments.length;
}
as defined here https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/arguments/length