myFunction.length in ECMAScript 262
The number of arguments declared with the function.
This property is read-only.
- Property Type
- Number
This property is informative only, since calls to functions may choose to not pass parameters which are declared (in which case the parameters have a value of undefined
inside the function), or may choose to pass more parameters than are declared (which may be accessed through the arguments
array inside the function).
function AddUpValues(){
var total=0;
for (var i=0,len=arguments.length;i<len;i++) total += arguments[ i ]*1;
return total;
}
var sum = AddUpValues(1,2,3,4,5,6,7,8,9);
var len = AddUpValues.length;
// ** sum is 45
// ** len is 0
function SayHi(firstName,lastName){
return "Hello "+firstName+" "+lastName;
}
var msg = SayHi();
var len = SayHi.length;
// ** msg is "Hello undefined undefined";
// ** len is 2