Hoisting
- JavaScript hoists function declarations and variable declarations to the top of the current scope.
- Variable assignments are not hoisted.
- Declare functions and variables at the top of your scripts, so the syntax and behavior are consistent with each other.
Shadowing
where you forget to put ‘var’, ‘let’, or ‘const’ in before a new variable declaration in a function, making the new variable GLOBAL by accident, or, overwriting a previously declared GLOBAL variable.
Ways to be explicit, and avoid scoping problems are found here
A JavaScript Fundamentals Cheat Sheet: Scope, Context, and “this” – Alexandra Fren