Alex Rivera | Logout

What happens when I call a Javascript function which takes parameters, without supplying those parameters?

Asked 2009-12-04T12:31:41.700
49

What happens when I call a Javascript function which takes parameters, without supplying those parameters?

Edit
Report

3 Answers

10

There is the inverse to everyones answer in that you can call a function that doesnt appear to have parameters in the signature with parameters.

You can then access them using the built in arguments global. This is an array that you can get the details out of it.

e.g.

function calcAverage() 
{ 
   var sum = 0 
   for(var i=0; i<arguments.length; i++) 
      sum = sum + arguments[i] 
   var average = sum/arguments.length 
   return average 
} 
document.write("Average = " + calcAverage(400, 600, 83)) 
answered 2009-12-04T12:43:46.673
4

In addition to the comments above, the arguments array has zero length. One can examine it rather than the parameters named in the function signature.

answered 2009-12-04T12:43:51.837
-8

You get an exception as soon as you try to use one of the parameters.

answered 2009-12-04T12:33:55.253

Your Answer