what is closure in javascript with example

1 year ago 71
Nature

In JavaScript, a closure is a function that has access to the variables and parameters of its outer function, even after the outer function has returned. In other words, a closure gives a function access to an outer functions scope from an inner function. Closures are created every time a function is created, at function creation time.

Here's an example of a closure in JavaScript:...