A function which is defined inside another function is known as inner function or nested functio n. Nested functions are able to access variables of the enclosing scope . Inner functions are used so that they can be protected from everything happening outside the function. This process is also known as Encapsulation .