To determine how many arguments were passed to a function?
Check the length, of the array like arguments variable, arguments.length.
To determine, how many variables, a function expects?
Write the name of the function, and retrieve its length property.
function sayHi() {
console.log(arguments.length);
for
(
var i=0, argumentsLength = arguments.length;
i < argumentsLength;
++i
)
{
console.log(arguments[i])
}
}
sayHi("Cat", "Alice")
//To determine how many arguments a function expects
console.log(sayHi.length);
http://javascript.info/tutorial/arguments
Tags: JavaScript
Leave a comment