DEV Community

davidka7
davidka7

Posted on

Whats a Closure in javascript?

From personal experience, I have noticed many developers know how to code, but don't really understand what happening in the back of the eye. One of those are Closures. Closures gives access to an outer functions scope(is what is created inside functions) through an another function inside of it(a nested function inside of the outer function). A way to know if it's a closure is if theres a variable defined not inside the function and is given from somewhere else.
Instead of explaining it with words I believe it'll be easier to understand it from code. I will set an example.

Alt Text
Alt Text

Top comments (0)