tags:

views:

116

answers:

4
+1  A: 

I would interpret this as:

If _gaq already stores a value that isn't convertible to false (e.g. a non-empty array), take that value; otherwise, make _gaq refer to an empty array."

Douglas Crockford writes the following about this in his book Javascript - The Good Parts:

The operator || can be used to define default values [...].

Some background info:

  • In JavaScript, there's quite a few values that evaluate to false in a boolean expression; suspects are the number 0, the empty string, NaN, the undefined value (note that undefined is not a keyword!), and false itself.

  • AFAIK, JavaScript's logical OR (||) operator uses short-circuiting, i.e. if the first term in an OR expression is true, the second one won't be evaluated.)

stakx
+7  A: 

it means assign _gaq the value of _gaq unless it is undefined, in which case _gaq will be an empty list.

Wayne Werner
Unless `_gaq` it's `undefined`, `null`, `0`, an empty string, `NaN` or `false`...
CMS
+2  A: 

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.

Ned Batchelder
+2  A: 
_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.

Matias
I think this is the best answer and deserves it to be marked as such (unless mentioned code *is* run in global scope, and I think it is). It clearly elaborates CMS' comment on the question. +10 if I could.
Marcel Korpel