Exit Scope
Whether you use the classic module format (browser or Node), CommonJS format (in Node), or ESM format (browser or Node), modules are one of the most effective ways to structure and organize your program’s functionality and data.
The module pattern is the conclusion of our journey in this book of learning how we can use the rules of lexical scope to place variables and functions in proper locations. POLE is the defensive private by default posture we always take, making sure we avoid over-exposure and interact only with the minimal public API surface area necessary.
And underneath modules, the magic of how all our module state is maintained is closures leveraging the lexical scope system.
That’s it for the main text. Congratulations on quite a journey so far! As I’ve said numerous times throughout, it’s a really good idea to pause, reflect, and practice what we’ve just discussed.
When you’re comfortable and ready, check out the appendices, which dig deeper into some of the corners of these topics, and also challenge you with some practice exercises to solidify what you’ve learned.