I'm writing a script that I want to keep from polluting the rest of the DOM, it will be a 3rd party script to collect some basic visitor analytic data.
I usually create a pseudo "namespace" using something like: var x = x || {};
Some of the other peoples code I'm looking at uses: x = window.x || {};
I know that not setting var
will set a global var. Is that the only difference?
I'm examining the two objects in Chrome and Webstrom and they look identical.
Can someone explain the difference between these two approached and the implications of using one over the other (if there is one)?
As I said, when I examine the objects that get created they look identical to me but I’ve learned with JS... appearances can be deceiving.