When JavaScript was born, its role was very limited. It was mainly used for event handling and for some visual effects, acting as the glue between the user and the HTML document. Usually, this purpose did not require too much code and most of its organization relied on functions and files. The global scope was the natural living environment of publicly accessible variables and functions.
With the growth of JavaScript's capability, the evolution of object models and the spread of the language also in a context different from the browser, the importance of JavaScript's role has grown as well, and so has the code size. What once was a simple set of scripts, now has become an application. The global scope is no longer a suitable environment to put code without criteria.
The use of global scope has always been an anti-pattern in any programming language for various reasons:
Understandability issues: When the code size of an application is not trivial, reasoning about a snippet...