Link to home
Start Free TrialLog in
Avatar of Sometimes
Sometimes

asked on

optional variable in javascript

Is there there a way to specify an optional variable in a function call, then set it to a value if nothing is passed through

ie

function test(variable1, variable2 optional=0 )

then used test(1)

variable1 = 1 and variable2 = 0


Thanks
ASKER CERTIFIED SOLUTION
Avatar of Roonaan
Roonaan
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Sometimes
Sometimes

ASKER

but in this case test(,12) doesn't work
No it doesn't. You could however always use: test(null, 12) and add an additional if-clause to the test() function.

Having calls like test(,,,,,12) however sound a bit VB-ish to me.. :^)

-r-