Writing large programs in JavaScript without modules would be pretty difficult. Imagine you only have the global scope to work with. This was the situation in JavaScript before modules. Scripts attached to the DOM were prone to overwriting each other and variable name conflicts. With JavaScript modules, you have the ability to create private scopes for your code, and also explicitly state which parts of your code should be globally accessible. JavaScript modules are not just a way of splitting code across files, but mainly a way to design boundaries between parts of your system. Behind every technology, there should be a guide for its use. While JavaScript modules make it easier to write “big” programs, if there are no principles or systems for using them, things could easily become difficult to maintain. How ESM Traded Flexibility For “Analyzability” The two module systems in JavaScript are CommonJS (CJS) and ECMAScript Modules (ESM). The CommonJS module system was the first JavaScript module system.…