scope

    [드림코딩/코딩앙마] scope와 hoisting, 그리고 TDZ (추가)

    scope 변수의 '수명' local scope global scope 1. local scope 지역변수(Local Variable)가 가지는 범위로, 함수가 실행되면 만들어지고 함수가 종료되면 소멸한다. 함수 외부에서는 접근할 수 없다. 2. global scope 전역변수(Global Variable)가 가지는 범위로 변수가 함수 외부에서 선언되어 프로그램 전체에서 접근할 수 있다. let globalMsg = 'global'; // global variable function printMsg() { let msg = 'hello'; console.log(msg); // local variable console.log(globalMsg); // 정상작동한다. } printMsg(); console...