단단한어린이·2022년 4월 9일


목록 보기

A scope is a rule for finding the identifier to be referenced. JavaScript follows this rule to find an identifier.

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.

Most C-family languages follow the block-level scope. A block-level scope means a scope valid within a code block. Here, "valid" means "referenceable". On the other side, JavaScript follows the function-level scope. A function-level scope is that a variable declared within a function code block is valid only within a function code block and is not valid outside the function (it cannot be referenced).
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.

Footprints in Coding

0개의 댓글