Closures are one of the most frequently misunderstood or barely ever undstood concept by beginner Javascript programmers. I personally believe that you will have a lot of "Oh, I see!" moments after you fully understand it. You will be capable of understanding certain things that previously didn't make sense to you because I assure you 100% that you've been using closures without even knowing it!
If you do not understand closures, please readthis article, it gives you good understanding of what a normal function is and how it's execution takes place, then explains to you what a closure is. It's big but it will without doubt be an efficient use of time.
Could I roughly boil that article down to: closures a) have access to outside variables, but restrict inside variables and b) provide a new `this` context?
I generally agree in terms of code style, but many beginners wonder why `this` keeps changing and that's usually a result of a closure. The most typical solution of course is an arrow function but that syntax is an ES6 luxury.
152
u/[deleted] May 28 '19
Closure is a concept I see lots of beginners struggle with. You can massively speed up dev time once you grasp how it works in JS.