Possible Duplicate:
What does "var FOO = FOO || {}" mean in Javascript?
I don't understand that :
var gapi = window.gapi||{};
Can you explain me? gapi is a bool?
Possible Duplicate:
What does "var FOO = FOO || {}" mean in Javascript?
I don't understand that :
var gapi = window.gapi||{};
Can you explain me? gapi is a bool?
It means if the variable gapi exists already, and its value does not evaluate to a boolean false one, assign that to the variable gapi otherwise assign a new object to it.
This practice is helpful to avoid overwriting of variables.
These are the JavaScript values that evaluate to boolean false:
falseundefinednull0NaN"")The logical or stops if the first symbol evaluates to something different from a truly value, like, false, undefined, null, '' or 0.. Otherwise it takes the second argument.
In this case, if gapi is not a global object defined in window, it assigns to gapi the new empty object {}.