Understanding the JavaScript Closures

Understanding the JavaScript Closures

What is a closure?

A closure is an inner function that has access to the outer/enclosing function’s variables scope chain.
Closure has three scope chains i.e.,
1) It has access to its own scope (variables defined between its curly brackets)
2) It has access to the outer function’s variables, and
3) It has access to the global variables.

The inner function has access not only to the outer function’s variables, but also to the outer function’s parameters.

Note that the inner function cannot call the outer function’s arguments object; however, even though it can call the outer function’s param’s directly.

In simpler way to say what is closure? If you create a function inside / within another function its called as closure / private function.

Understanding the JavaScript Closures

An Example of Closures in JavaScript:


Will come up with next article on this with more details of closures and some more example’s & Closures’ Rules and Side Effects, usage and so on….
You can find more even in W3C about closures:
URL : http://www.w3schools.com/js/js_function_closures.asp

Leave a Reply

Time limit is exhausted. Please reload CAPTCHA.