Possible Duplicate:
How do I make a default value for a parameter to a javascript function
in PHP:
function func($a = 10, $b = 20){
// if func() is called with no arguments $a will be 10 and $ b will be 20
}
How can you do this in JavaScript?
I get a error if I try to assign values in function arguments
missing ) after formal parameters
In javascript you can call a function (even if it has parameters) without parameters.
So you can add default values like this:
and then you can call it like
func();to use default parameters.Here’s a test: