Everyone else has already mentioned the pollution of the name of the global and globally evil , even OP:
Or is it cluttering the global reach ...
but there is one more reason.
There is only one instance of a global variable. This makes it not scalable enough. If at some point in the future you need more than one instance of an object, you will need to create a second global variable or convert the original variable into an array and manage this array manually (i.e. decide for yourself when to delete the object from memory).
If it has already been created by closure, then the creation of the second, third and fourth instances can simply be done by calling a function that creates the closure again and again. You also get the added bonus that all created instances automatically collect garbage when they are no longer needed.
This situation happens more often than you think. Imagine that you just created an animation sequence, an animation of text, for example, to disappear. And you used a global variable to track the state of the animation. And you think this is great and good, and forget about it. Then after some time, your boss comes to you and says that he likes the animation, and would like to add it to other things on the page. Now you need to deal with the processing of several animations at the same time and you need to convert this global array to an array so that one animation does not knock the other current animation .. if they were encapsulated in closure to start with ...
And what do you know, just as I was scrolling after I submitted this answer, I found a question illustrating the problem with global variables: How to create multiple timers on the same page that work independently - javascript? . Although you really don't need to close for this particular problem, it's just plain old variables.
source share