Why would one write global code inside a function definition-call pair?
- by ssg
I see examples where JavaScript code including jQuery and jslint use the notation below:
(function(){
// do something
})();
instead of:
// do something
I first thought this is just for local scoping, i.e. creating local variables for the code block without polluting global namespace. But I've seen instances without any local variables at all too.
What am I missing here?