We rarely worry about code organization for simple scripts, since a few lines of code may be immediately identified and possibly changed without any issues. But when the codebase of our application grows, the need to organize our code becomes increasingly urgent. In this chapter, we will describe the most common ways to face this problem starting from namespaces through the ECMAScript 6 modules. In the middle, we will explore the different approaches to define organizational units of the code that fit on the server-side and on client-side the JavaScript programming.
The following topics will be discussed in the chapter:
The global scope
The namespace pattern
The module pattern
Approaches to JavaScript modularization (AMD and CommonJS)
ES6 modules