Nested function

In computer programming, a nested function (or nested procedure or subroutine) is a named function that is defined within another, enclosing, block and is lexically scoped within the enclosing block – meaning it is only callable by name within the body of the enclosing block and can use identifiers declared in outer blocks, including outer functions. The enclosing block is typically, but not always, another function.

Programming language support for nested functions varies. With respect to structured programming languages, it is supported in some outdated languages such as ALGOL, Simula 67 and Pascal and in the commonly used JavaScript. It is commonly supported in dynamic and functional languages. However, it is not supported in some commonly used languages including standard C and C++.

Other programming technologies provide similar benefit. For example, a lambda function also allows for a function to be defined inside of a function (as well as elsewhere) and allows for similar data hiding and encapsulation. Notably, a lambda function has no name (is anonymous) and therefore cannot be called by name and has no visibility aspect.


Developed by StudentB