ajax333221 ajax333221 - 9 days ago 5
Javascript Question

How to pass the value 'undefined' to a function with multiple parameters?

I want to pass the value of 'undefined' on a multiple parameter function but without omitting the parameter.

What do I mean with "without omitting the parameter". I mean that we should not just omit the

parm2
like this example:

function myFunction (parm1, parm2) {}
myFunction("abc");


This will indeed make
parm2
undefined, but however I am not allowed to do it this way because I will need to specify other parameters AFTER the omitted parameter.

So in the case I want to make
parm1
undefined BUT also want to have other parameters after this one to hold a value won't work with the previous method.

I have tried with:

myFunction( ,"abc"); //don't seem to work


And:

myFunction(undefined,"abc"); //neither work

Answer

A better approach might be passing Object with named attributes and then look for those specific attribute values. This way you don't have to be dependent on number of arguments.

Comments