One of the best practices in javascript programming is avoiding global variables(they are evil), if you happen to have multiple javascript files from multiple authors they will lead to a name collision and hence unexpected result. Fortunately, there are great tools that would help us detect them.
It can be avoided by wrapping variables and functions in to an object. Anonymous functions are elegant ways of wrapping global variables and functions , and executing them immediately.
var isIE = !!document.all;
var div = document.getElementById(“xyz”);
div.style.height = ….
})();
It will be very helpful to execute a block of initialization scripts, augmenting an existing object or setting it properties when a .js file is loaded.