Any code thats written inside {} of loops,functions or if statements is block scope.
If you will declare let/const variable inside brackets that would make it block scope which means it can only be seen or accessed from inside not outside.
This works this way with let/const variables if you will declare var variable it can be seen from outside because var itself is function scoped variable type and it can be seen from outside.
let/const Example :
let/const variables that are declared inside {} can be only accessed inside {} not outside of it thats what makes it block scope.this example will throw an error
var Example :
Var variable work differently therefore this wont throw an error. however using var is not best practice in general.
LEXICAL SCOPE
Any variable declared inside {} can see other glocal variable that are declared outside of {}.
But global variables cant see local variables and they cant access them.this logic works for let/const.
Only way global variables can access the local ones is if the local variable is var variable and it only works this way on var variable.
Example :
The x variable in this photo cant be accessed globally because its declared inside {}. however color variable can be accessed inside {} because the color variable is declared globally and can be used in other functions or loops as well.