In PHP, I can have a function default to a value in a parameter.
Example:
function func($a = 1, $b = 2) {
return $a + $b;
}
What about JavaScript? Can I make the same statement in Firefox 39
;
function b (a=1) {
return a;
}
But the recommendation I always see is:
function b (a) {
a = a || 1;
return a;
}
-
Why do not they use the default definition of a parameter, as it does in PHP, since it is possible to do this?
-
Is there any restriction on the browser version that is used?
Note : When you said which is the safe way , I mean the security that something will work in any browser, regardless of the version.