@accolades_dev Caveat: javascript has var, let, and const. Var is function/globally scoped and let and const are block scoped. So the bahavior is a little different here. Understanding hoisting in this context is a help as well.
@accolades_dev A variable, function, or object is only accessible to the code within the scope where it was declared. The scope can be many things though; Global scope, function scope, and block scope.
It matters not how strait the gate,
How charged with punishments the scroll,
I am the master of my fate,
I am the captain of my soul.
- William E. Henley