Both the functions can use the variable 'a' since its global. But what if you want to exclusively use it for one of the methods. How can you do that? Well closures make that possible. Its a global variable but only that function can access and write on it.
functionaddOne(){vara=0;returnfunction(){returna+=1;}};varincrement=addOne();increment()// after this a's value will be 1increment()// a will be 2
Here 'a' is a global variable but only increment function has access to it. There is nothing more to closure.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
A 5 year old may not understand this unless he/she has an understanding of global variables.
Take this piece of code
Both the functions can use the variable 'a' since its global. But what if you want to exclusively use it for one of the methods. How can you do that? Well closures make that possible. Its a global variable but only that function can access and write on it.
Here 'a' is a global variable but only increment function has access to it. There is nothing more to closure.