18.7 Nested Functions
Nested functions, also known as inner functions, are functions defined within the scope of another function, often referred to as the enclosing or outer function. This powerful construct allows for sophisticated code organization, encapsulation, and the creation of closures, which are functions that “remember” the environment in which they were created. The primary reason nested functions exist is to leverage lexical scoping, a fundamental principle where an inner function has access to the variables and parameters of its outer function, even after the outer function has finished executing.