The variable has a scope by the declaration position. That is, the variable declared globally is a global variable with a global scope, and the variable declared locally becomes a local variable with a regional scope.
However, if you use the let keyword, you can use the block level scope.
The global variable x and the local variable x were declared redundant. If the variable names are duplicated, refer to the local variable first.