In the following function:
foo = function(a){
if (!a) a = "Some value";
// something done with a
return a;
}
When “a” is not declared I want to assign a default value for use in the rest of the function, although “a” is a parameter name and not declared as “var a”, is it a private variable of this function? It does not seem to appear as a global var after execution of the function, is this a standard (i.e. consistent) possible use?
It’s a private variable within the function scope. it’s ‘invisible’ to the global scope.
As for your code you better write like this
Because
!acan be true for0, an empty string''or justnull.