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.

12

u/razorsyntax May 28 '19

I never understood why we don’t call closures “scope”? What’s the difference between closures and scope in, say, C++ or Java?

5

u/Candyvanmanstan May 28 '19

Because closure and scope isn't the same in javascript either. A closure can have access to three scopes. It's own scope, an outer functions scope, and global variables.

1

u/maher321 May 28 '19

Is a global not just an outer function scope? Like the window object in a browser is just the most outer one so all child functions have access to its properties.