var
will not "shadow" a local variable in the same scope. Likewise, var
will not "shadow" a parameter (which is a local variable/binding itself). Simply, each time the function is invoked, callback
represents a different local variable which initially contains the first argument passed; and there is only one local variable called callback
.
Because var doesn't "create" a new variable (search for "hoisting"),
function (callback) {
var callback = callback || false;
and
function (callback) {
callback = callback || false;
are equivalent - no difference. (Although I find the latter more clear.)
However, removing the callback = callback || false
changes the semantics. In particular, callback may end up with false-y values like 0 without that line. Whether or not this is needed/useful here is a different issue as (false).apply(..)
will still result in an error.
Here is a simple TTL for x || y
:
x y x || y
------- --- ------
TRUTH-y ANY x
FALSE-y ANY y