explaining closures to a 10 Years old kid.
Let's say that you have a box of candy in the living room (global variable).
And you are sitting in your room but you cannot access it, and nobody is allowed to access it except your brother, so you ask your brother to bring the candy to you thats what is called closures.
Assume you are main function and you recall your brother to bring the candy from the living room to you.
So just to recap closures are main function containing another function and we made the main function to nest the global variable and not make it accessible to others
No comments:
Post a Comment