The cookiepath
variable is being declared, an initialized.
The var
statement doesn't make any harm if an identifier was already declared in the current lexical scope.
If cookiepath
wasn't declared yet, the var
statement, before run-time, will initialize the variable to undefined
.
After that, in run-time, the assignment is made, if it's value is falsy (other than null
, undefined
, an empty string, 0
, NaN
, or false
) it's set to an empty string.
Keep in mind that you have access to the cookiepath
variable in the local scope.
Consider the following example:
var cookiepath = 'outer';
(function () {
var cookiepath = cookiepath || "";
alert(cookiepath); // alerts an empty string, not "outer"
})();
In the above example, we have a global cookiepath
variable, on the global scope, but when the function is executed, a local cookiepath
variable will be declared on the scope of the function, and this shadows the value of the outer scope, and this behavior is noticeable even before the var
statement in the function, e.g.:
var foo = 'foo';
(function () {
alert(foo); // undefined, not 'foo' from the outer scope
var foo; // undefined
})();