자바스크립트에는 세 가지의 스코프가 존재 전역 스코프 (Global Scope) 함수 스코프 (Function Scope) 블록 스코프 (Block Scope)

전역 스코프 (Global Scope)

var msg = "전역 변수";

함수 스코프 (Function Scope)

function func() {
    var msg = "로컬 변수";
}
func();
console.log(msg); // ReferenceError: msg is not defined

블록 스코프 (Block Scope)

{
    let msg = "블록 스코프";
}
console.log(msg); // ReferenceError: msg is not defined