자바스크립트에는 세 가지의 스코프가 존재 전역 스코프 (Global Scope) 함수 스코프 (Function Scope) 블록 스코프 (Block Scope)
var msg = "전역 변수";
function func() {
var msg = "로컬 변수";
}
func();
console.log(msg); // ReferenceError: msg is not defined
let
과 const
로 선언한 변수={
let msg = "블록 스코프";
}
console.log(msg); // ReferenceError: msg is not defined