JavaScript modules 101
The practice of breaking down programs and libraries into modules is called modular programming.
In JavaScript, a module is a collection of related objects, functions, and other components of a program or library that are wrapped together and isolated from the scope of the rest of the program or library.
A module exports some variables to the outside program to let it access the components wrapped by the module. To use a module, a program needs to import the module and the variables exported by the module.
A module can also be split into further modules called sub-modules, thus creating a module hierarchy.
Modular programming has many benefits. Some benefits are as follows:
- It keeps our code both cleanly separated and organized by splitting it into multiple modules
- Modular programming leads to fewer global variables, that is, it eliminates the problem of global variables, because modules don't interface via the global scope, and each module has its own scope
- It makes code...