Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
The arguments object has a unique
length property. While you might think
this length property will give you the number of defined arguments, it
actually gives the number of parameters sent to the function during
invocation.
<!DOCTYPE html><html lang="en"><body><script>
var myFunction = function(z, s, d) {
return arguments.length;
};
console.log(myFunction()); /* logs 0 because no parameters were passed
to the function */
</script></body></html>
Using the length property of all
Function() instances, we can actually
grab the total number of parameters the function is expecting.
<!DOCTYPE html><html lang="en"><body><script>
var myFunction = function(z, s, d, e, r, m, q) {
return myFunction.length;
};
console.log(myFunction()); // logs 7
</script></body></html>