let name1;
let name1 = value1;
let name1 = value1, name2 = value2;
let name1, name2 = value2;
let name1 = value1, name2, /* …, */ nameN = valueN;
let a = 10;
console.log(a); // 출력: 10

let b;
console.log(b); // 출력: undefined
if () { // if 블록
    // ...
} else { // else 블록
    // ...
}

function exampleFn() { // 함수 블록
    // ...
}

{ // 임의의 독립적인 블록 (일반적으로 잘 사용되지는 않음)
  let temp = 10; // temp는 이 블록 내에서만 유효
}

for () {  // for 블록
    // ...
}
if (true) let a = 10; // Uncaught SyntaxError: Lexical declaration cannot appear in a single-statement context
/*  글로벌(전역) 스코프 */
let globalVar = "글로벌 변수"; // 이 파일(또는 스크립트)의 최상위 블록 전체에서 유효함

function exampleFunction() {
    /* 함수 블록 스코프 */
    let functionVar = "함수 블록 변수"; // 함수 전체 블록에서 유효함

    if (true) {
        let innerBlockVar = "if 블록 변수"; 
        console.log(functionVar);   // 출력: "함수 블록 변수"
        console.log(innerBlockVar); // 출력: "if 블록 변수"
    }

    // if 블록 스코프 외부이므로 참조 불가
    // console.log(innerBlockVar); // ReferenceError (innerBlockVar is not defined)
}

if (true) {
    let ifBlockVar = "if 블록 변수";
    console.log(ifBlockVar); // 출력: "if 블록 변수"
}

exampleFunction();

console.log(globalVar); // 출력: "글로벌 변수"

// console.log(functionVar); // ReferenceError (functionVar is not defined)
// console.log(ifBlockVar); // ReferenceError (ifBlockVar is not defined)
// 같은 스코프 내에서 let 동일한 식별자(변수 이름)로 변수를 다시 선언하면 오류가 발생
let exampleLet = 10;
let exampleLet = 100; // Uncaught SyntaxError: Identifier 'exampleLet' has already been declared
 // 서로 다른 스코프 내에서 let 동일한 식별자(변수 이름)로 변수를 다시 선언은 가능
let exampleLet = 10;
console.log(exampleLet); // 출력: 10

if (true) {
    let exampleLet = 100;
    console.log(exampleLet); // 출력: 100
}

console.log(exampleLet); // 출력: 10
// 글로벌 스코프
let globalVar = "글로벌 변수";
console.log(globalVar); // "글로벌 변수"

// 재할당 가능
globalVar = "재할당된 글로벌 변수";
console.log(globalVar); // "재할당된 글로벌 변수"

if (true) {
    // 블록 스코프
    let blockVar = "블록 변수";
    console.log(blockVar); // "블록 변수"

    // 재할당 가능
    blockVar = "재할당된 블록 변수";
    console.log(blockVar); // "재할당된 블록 변수"
}

// 블록 밖에서는 참조 불가
// console.log(blockVar); // ReferenceError
// 모듈 내부에서 let 선언
let globalVar = "모듈 내부 글로벌 변수";

function exampleFunction() {
    let functionVar = "함수 내 변수";
    console.log(functionVar); // 출력: "함수 내 변수"
}

console.log(globalVar); // 출력: "모듈 내부 글로벌 변수"

// 모듈 외부에서 globalVar 접근 시
// 브라우저: window.globalVar → undefined
// Node.js: global.globalVar → undefined
// TDZ 영역 시작
// ↓
console.log(myVar); // ReferenceError: Cannot access 'myVar' before initialization
// ↑
// TDZ 영역 종료

let myVar = 10;