optional arguments to a function in javascript
Is this possible? Can I specify a default value a la:
function foo(mode = 'input', teeth = 'yellow') {
do some stuff
}
?
muppet
January 27th, 2006 11:17am
Nope, you want python.
:-)
well I can do it in perl and PHP just fine, Simon, so I don't need python. I was just curious if javascript allowed it.
muppet
January 27th, 2006 11:19am
Arguments are optional - callers can call with less or more parameters and there will be no errors, but the undefined parameters will be...undefined. So you could set the defaults simply by checking if it's undefined.
Alternately look at the arguments array.
That's good enough.
muppet
January 27th, 2006 11:21am