JScript function..

  • Thread starter Thread starter Chuck Thomos
  • Start date Start date
C

Chuck Thomos

Does the number of arguments defined in the Jscript function should match
the number of arguments while calling the function should match?

I am seeing in my test that it is not required to match.

Thanks,

C Thomos
 
No they must not match, and since jscript/javascript don't support
overloading, we can deduce from this that it simply matches the name of the
function and not the parameters.

Interestingly, every function has a variable called "arguments" explicitely
defined, which you can use to access any excess parameters:

function test(){
for (var i = 0; i < arguments.length; ++i){
alert(arguments);
}
}

test('a', 'b');

will actually display "a" then "b". I'm not sure what the support for this
is (ie, mozilla, opera, ...)

Karl
 
Chuck said:
Does the number of arguments defined in the Jscript function should match
the number of arguments while calling the function should match?

I am seeing in my test that it is not required to match.

JavaScript (and JScript) do not check that the number arguments of
passed in to a function call match the number in the function definition.

If you pass fewer arguments in the function call, then the parameters
which do not have corresponding arguments will be 'undefined'.

If you pass more arguments, then those additional arguments will be
accessible only via the 'arguments' object.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top