Friday, 16 March 2018

How to understand closures in Javascript?

How can one understand closures in Javascript?




In general terms, a closure is a function bound to one or more external variables. When it is called, the function is able to access these variables. In JavaScript, closures are often implemented when functions are declared inside another function. The inner function accesses variables of the parent one, even after the parent function has terminated




In this statement, "a closure is a function bound to one or more external variables", does it mean we can do this : var myFun = Function(msg){...}; is it correct ?




What does it mean "even after the parent function has terminated"?

No comments:

Post a Comment

casting - Why wasn't Tobey Maguire in The Amazing Spider-Man? - Movies & TV

In the Spider-Man franchise, Tobey Maguire is an outstanding performer as a Spider-Man and also reprised his role in the sequels Spider-Man...