Modularity structures JavaScript programs as separate areas of code with focused responsibilities and controlled access to data and behavior. It supports clear separation of concerns while offering several implementation choices rather than one mandatory object model. section 1.0 section 6.2
Before native module specifications, JavaScript code commonly shared the global space across script files. Function scope provided a practical boundary for isolating code, encapsulating data and behavior, and avoiding name clashes. section 6.2
Pre-module JavaScript uses several modular patterns:
- Object namespaces organize related values under a shared object. section 6.2
- Immediately Invoked Function Expressions create isolated scopes for code and private state. section 6.2
- IIFE mixins, factory functions, and related patterns provide alternative ways to package behavior. section 6.2
A script without a module system
Instead of placing every application value in the global space, a script can use a function-created scope to keep implementation details isolated and expose only the behavior it needs to share. section 6.2
Modularity also connects to composability: decomposing code into fine-grained behavior makes functional code easier to compose and reason about. The boundary is therefore both organizational and behavioral. section 4.9









