-3

So I'm an analyst and, while my job does not require I know Javascript it'd sure help. I'd like to understand fuller the Google Analytics snippet.

I'm looking at a Google Analytics Snippet:

var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-xxxxxxxx-1']);
  _gaq.push(['_setDomainName', 'example.com']);
  _gaq.push(['_trackPageview']);

According to W3 Schools gaq is an object, in this instance it appears to be an array. The first value in the array is gaq.push set account. Fine.

But what are the "|| [ ];" on the first line?

Doug Fir
  • 19,971
  • 47
  • 169
  • 299

1 Answers1

2

It means that if _gaq is undefined then set it to be an empty array.

Matt Cain
  • 5,638
  • 3
  • 36
  • 45
  • Thanks for the answer. So the double bar || means "empty"? Good to know. – Doug Fir Aug 13 '13 at 13:35
  • 4
    No, they mean _or_ – so the result of that expression is either `_gaq`, if such a variable already exists and does not have a value that evaluates to false, _or_ a new empty array. – CBroe Aug 13 '13 at 13:38