I've been playing around with Node.js after having not used JavaScript for a long time.
One thing I've noticed is that many of the sample files I've been looking at use the following convention:
(function() {
... all javascript code for the file ...
})();
Is there a reason to enclose all the JavaScript in a file in a function like that, or is it just convention? Is it something I should mimic?
I should also note, that at least in the files I've been playing with, the code works the same way with or without the function surrounding everything.
Thanks for your insights!