DEV Community

skptricks
skptricks

Posted on

Understanding closures in JavaScript

Post Link : Understanding closures in JavaScript

In this tutorial we are going to discuss what is closure in javascript. A Closure is the aggregate of functions clumped together with the references to its surrounding environment. It gives you an outer function’s scope from an internal function. Scopes are contexts of variables.

What is a closure?
A closure is a feature in JavaScript where an inner function has access to the outer (enclosing) function’s variables — a scope chain.
The closure has three scope chains:
it has access to its own scope — variables defined between its curly brackets
it has access to the outer function’s variables
it has access to the global variables

When to use Closure?
Closure is useful in hiding implementation detail in JavaScript. In other words, it can be useful to create private variables or functions.

Understanding closures in JavaScript

Top comments (1)

Collapse
 
dance2die profile image
Sung M. Kim • Edited

Hi @skptricks .

I think the post has only a summary, which happens when your RSS feed option is set to export only summary, not full text.

If you are using WordPress, this post might be of help.