Possible Duplicates:
In Javascript, what does it mean when there is a logical operator in a variable declaration?
what’s the javascript “var _gaq = _gaq || []; ” for ?
what does this javascript syntax mean?
var _gaq = _gaq || [];
Possible Duplicates:
In Javascript, what does it mean when there is a logical operator in a variable declaration?
what’s the javascript “var _gaq = _gaq || []; ” for ?
what does this javascript syntax mean?
var _gaq = _gaq || [];
it means assign _gaq the value of _gaq unless it is undefined, in which case _gaq will be an empty list.
It's a short way to set _gaq to an empty array if _gaq is undefined. It's probably used to provide a default value for an argument to a function.
_gaq || []
Is an expression that will return _gaq if it's a non-false value ( I mean is not 0, nor false, nor '') or an empty array in the other case.
var _gaq = _gaq || [];
Always will set [] to _gaq. I tested it in this way from my firebug console:
_gaq = 'crazy value';
(function(){var _gaq = _gaq || [];
console.log(_gaq);
})();
Having in mind that _gaq could be a variable defined in the global namespace. But is not the case.