It's tricky to tell exactly what's happening because the code is obfuscated through compilation, but as best I can tell, it's using the `answer` value to prevent another global from making it seem like the Analytics code has already been initialized.
There is a JavaScript object representing all of the Google Analytics state and functions. When this object is set up, they add the property "answer = 42" to it. Then, before making this object globally accessible at `window.ga`, they double check that `window.ga` does not yet exist or that `window.ga.answer` does not equal 42. If it already equals 42, then the initialization must have already happened (maybe the Analytics code was included twice?), and so it doesn't proceed to clobber that already-initialized global Analytics state. Checking that the `window.ga` variable doesn't exist is not quite enough, since other JavaScript on the page may have set that property for some reason (of course, this logic wouldn't work if other code on the page had simple set `window.ga.answer = 42`, but that's unlikely to happen by accident). As long as it looks like the initialization hasn't already run, then it goes ahead and does the initialization and makes the result globally accessible at that point.
tl;dr: It's not just a joke; it's actually used to make it less likely that other JavaScript on the page hasn't created a global variable called `ga` which may otherwise prevent the Analytics code from running.
An identifier must start with $, _, or any character in the Unicode categories “Uppercase letter (Lu)”, “Lowercase letter (Ll)”, “Titlecase letter (Lt)”, “Modifier letter (Lm)”, “Other letter (Lo)”, or “Letter number (Nl)”.
$ itself doesn't really mean anything special in javascript.
jQuery and other libraries often use $ as their main object, so it's probably best to avoid using it unless you need to or it's wrapped in another function.
That's not really what the Hitchhikers Guide to the Galaxy said - rather, 42 is the answer to the ultimate question of life, the universe and everything. But since we don't know what the question is... Very different from the answer to everything.
[+] [-] timothya|12 years ago|reply
There is a JavaScript object representing all of the Google Analytics state and functions. When this object is set up, they add the property "answer = 42" to it. Then, before making this object globally accessible at `window.ga`, they double check that `window.ga` does not yet exist or that `window.ga.answer` does not equal 42. If it already equals 42, then the initialization must have already happened (maybe the Analytics code was included twice?), and so it doesn't proceed to clobber that already-initialized global Analytics state. Checking that the `window.ga` variable doesn't exist is not quite enough, since other JavaScript on the page may have set that property for some reason (of course, this logic wouldn't work if other code on the page had simple set `window.ga.answer = 42`, but that's unlikely to happen by accident). As long as it looks like the initialization hasn't already run, then it goes ahead and does the initialization and makes the result globally accessible at that point.
tl;dr: It's not just a joke; it's actually used to make it less likely that other JavaScript on the page hasn't created a global variable called `ga` which may otherwise prevent the Analytics code from running.
[+] [-] mar1|12 years ago|reply
[+] [-] judk|12 years ago|reply
[+] [-] pepon|12 years ago|reply
[+] [-] unknown|12 years ago|reply
[deleted]
[+] [-] jt2190|12 years ago|reply
[1] For those not in on the joke: http://en.wikipedia.org/wiki/42_(number)#The_Hitchhiker.27s_...
[+] [-] Aurel1us|12 years ago|reply
From: http://stackoverflow.com/questions/1661197/valid-characters-...
[+] [-] dm2|12 years ago|reply
$ is a function object.
$.answer is a property of that object.
$ itself doesn't really mean anything special in javascript.
jQuery and other libraries often use $ as their main object, so it's probably best to avoid using it unless you need to or it's wrapped in another function.
[+] [-] gprasanth|12 years ago|reply
[+] [-] currysausage|12 years ago|reply
[+] [-] Joshu42|12 years ago|reply
Even to check an instantiation ...
[...] [...] [...][+] [-] dkersten|12 years ago|reply
That's not really what the Hitchhikers Guide to the Galaxy said - rather, 42 is the answer to the ultimate question of life, the universe and everything. But since we don't know what the question is... Very different from the answer to everything.
[+] [-] Tarang|12 years ago|reply
[+] [-] iM8t|12 years ago|reply
[+] [-] a-l-c-o|12 years ago|reply
0.0.0.0 google-analytics.com
Maybe you forgot you do too ?
[+] [-] dudus|12 years ago|reply