The JavaScript uses the lexical scoping of variables. Simply the placement of the variable will determine who can access it. The access to the variable does not depend on how and when the code runs. Javascript determines the access of variables at compile time itself.
Play and Learn Here
var
keyword). They are only accessible inside the function and children functions in which we define the variable.{ }
. (using keywords let
and const
).