Javascript is by far the most popular language in the world and is used now … yes where it is not only used. Initially js was developed to bring a little interactivity to web pages (open alerts, ask questions, well, maybe “snowball for the site”) and it was in the distant 90s. However, web sites too quickly became a very popular way to deliver applications to the end user and the inherent capabilities quickly became overwhelming. Web-applications became more and more powerful, and there was more and more code. There was so much of it that it became more and more difficult to store it all in one or even several files. And working with an application split into hundreds of files became a huge problem because each file would have to be loaded through a script tag inserted into the page. This was a serious limitation compared to any other programming environment, where a program could consist of an unlimited number of files and a modular architecture was provided out of the box. But the more script tags there were, the more requests would have to be made before the application would start working, and hence the more time it would take before the first run.
Another serious limitation was that even if a modular system was introduced at the language level, it would not immediately appear to the application user, as it would require serious labor on the part of both the application developer and browsers (to finalize support for the standard).
However, the need was already there. Software developers couldn’t wait for javascript to have a modular system. And at that point, there was no indication that it would appear at all.
All js code that was loaded into the browser, all declared variables worked in a global context. This could lead to variable name conflicts during application development.
There was no guidance from the language developers and the community on how to structure their code, and the lack of modularity made js application development a living hell.
To realize the need for a modular approach, you need to understand that high complexity is ultimately inevitable for serious projects. One of the challenges that modularity solves is the ability to hide this complexity behind the simple (but importantly, well-designed!) interface that the module provides. Different modules should communicate with each other, and be grouped into other modules, only through this interface.
The modular approach should provide the ability to split the application into an unlimited number of submodules, providing the ability to define the dependencies of each module and their automatic loading into the runtime environment.
Due to the fact that the project is broken down into many small parts, the complexity of maintaining and developing the application as a whole is significantly reduced, because it is possible to assign work on different modules to different developers/teams, depending on the size of the code base.