r/javascript • • May 28 '19

What are some JavaScript things beginners don't know?

333 Upvotes

383 comments sorted by

View all comments

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.

23

u/priceLbear May 28 '19

A few weeks ago I spent some time learning about closure and I understand the concept. How exactly does it speed up dev time though? Do you use it often? If yes, could you describe some use cases I obviously fail to see?

1

u/8lbIceBag May 29 '19

It doesn't really. Maybe because everything is private and you don't have to use this everywhere or program as defensively?

In my experience, if you're someone building off or extending a library, it will slow you down. It sucks to extend a library or framework that uses closures because you don't have access to internals. Also closures are slower and more resource intensive (execution wise) if there's many instances.

Great for singletons or for your own libraries that no one has to extend though