JavaScript closures are a powerful yet sometimes misunderstood concept in JavaScript programming. Despite being a bit tricky to understand at first...
For further actions, you may consider blocking this person and/or reporting abuse
Unfortunately, this is not correct. Nesting functions has nothing to do with it. A closure is created every time a function is created, at the time of that function's creation.
Misconceptions About Closures
Jon Randy 🎖️ ・ Sep 27 '23
Thanks for the feedback. You're right that closures are created every time a function is created. However, my definition was emphasizing the common scenario where an inner function retains access to the outer function's variables even after the outer function has executed, highlighting the practical use of closures in nested functions.
Is a closure really created every time a function is created?
Creating functions and closures are not the same.
Yes. EVERY function has an associated closure, that is created when you create the function. There is no 'manual' way to create a closure, it happens automatically.
I just researched about your response, and you seem to be correct. This brings about certain confusion for me because now I think I don't know what I knew.
Why is a closure typically described as a function with reference to free variables? are you saying functions without free variables , functions with free variables are all closures?
Probably because there's a lot of incorrect information out there, or possibly because it is believed to be a simpler way to explain it (despite being wrong).
I'm saying closures ARE NOT functions. They are the mechanism by which functions retain access to variables in the lexical scope in which they were created. Every function has one. I hope this makes sense.
Also, I'm not sure what you mean by 'free variables'.
What a blog i clearly understand all these thing from here ,thank so much
Thank you! I'm glad to hear that
Thank you for your clear and concise explanations.your effort is highly appreciated !
Thank you for your kind words!
Well explained 👍
Thank you! Glad you liked it! 👍
❤️👏
❤️