I know of two methods of setting a default parameter, but I would like to know what the preferred method is.
function Foo(par1, par2)
{
if(par2 == null)
par2 = "my default"
}
or
function Foo(par1, par2)
{
par2 = par2 || "my default"
}
or is there a better way than either of these?
EDIT:
I would also like to know how others handle multiple optional parameters such as this: We have several functions like this in internal libraries (I think they're pretty ugly).
function Foo(par1, par2, par3)
{
if(par2 == null)
par2 = "my default"
if(par3 == null)
par3 = "my default"
// Do something
}
And to call it:
Foo("Parameter one",null,true)