Is this the correct way to check for a missing parameter in a function? Would this work in all browsers? How about IE?
function getName(name){ name = name !=
you can do:
name = name || 'default';
That says if name is undefined or falsy (null, 0, "", false, {}, []), set it to "default".
name
null
0
""
false
{}
[]
"default"
js(h|l)int will complain about it, but it works at least as far as back as IE7. It's not invalid code at all or relying on some undocumented behavior either.