r/JavaScriptTips • • Aug 06 '23

Javascript Variable Scope in 2.6 Minutes…

Here is a post about scoping and javascript variables. Differences in scope mean differences in accessibility and usability for the variables that we declare. I hope this post helps everyone learn or brush up on their knowledge when it comes to declaring variables. Please feel free to reach out with any questions, queries, comments or banter!

https://thecodingapprentice.substack.com/p/javascript-variable-scope-in-26-minutes?sd=pf

1 Upvotes

3 comments sorted by

1

u/DualFlush Aug 06 '23

Any variable (var, let or const) declared outside of functions or any block of code (not within curly brackets { }) is global scope.

Not if it's in an ES6 module.

1

u/[deleted] Aug 06 '23

Thanks for pointing this out, please can you expand?

1

u/DualFlush Aug 06 '23

Nothing in a module escapes the module unless it's both exported and imported.