const name1 = value1;
const name1 = value1, name2 = value2;
const name1 = value1, name2 = value2, /* …, */ nameN = valueN;
const age = 30;
const age; // Uncaught SyntaxError: Missing initializer in const declaration
if () { // if 블록
    // ...
} else { // else 블록
    // ...
}

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

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

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

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

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

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

if (true) {
    const 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)
// 같은 스코프 내에서 const 동일한 식별자(변수 이름)로 변수를 다시 선언하면 오류가 발생
const exampleConst = 10;
const exampleConst = 100; // Uncaught SyntaxError: Identifier 'exampleConst' has already been declared
 // 서로 다른 스코프 내에서 const 동일한 식별자(변수 이름)로 변수를 다시 선언은 가능
const exampleConst = 10;
console.log(exampleConst); // 출력: 10

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

console.log(exampleConst); // 출력: 10
const exampleConst = 10;

/* 동일한 식별자로 할당 연산자(=)를 사용한 변수의 값을 변경할 수 없습니다. */
exampleConst = 100; // Uncaught TypeError: Assignment to constant variable.
// 일반 객체 선언
const person = {
    name: 'Alice',
    age: 30
};

// 1. 속성 추가
person.city = 'Seoul'; // 새로운 속성 추가
console.log(person); // 출력: { name: 'Alice', age: 30, city: 'Seoul' }

// 2. 속성 업데이트
person.age = 31; // 기존 속성 값 업데이트
console.log(person); // 출력: { name: 'Alice', age: 31, city: 'Seoul' }

// 3. 속성 제거
delete person.city; // 속성 제거
console.log(person); // 출력: { name: 'Alice', age: 31 }
// Set 선언
const numberSet = new Set([1, 2, 3]);

// 1. 값 추가
numberSet.add(4); // Set에 새로운 값 추가
console.log(numberSet); // Set { 1, 2, 3, 4 }

// 2. 값 제거
numberSet.delete(2); // Set에서 값 제거
console.log(numberSet); // 출력: Set { 1, 3, 4 }

// 3. 값 존재 여부 확인
console.log(numberSet.has(3)); // 출력: true
console.log(numberSet.has(2)); // 출력: false
// Map 객체 선언
const userMap = new Map();
userMap.set('name', 'Alice');
userMap.set('age', 30);

// 1. 키·값 쌍 추가
userMap.set('city', 'Seoul');
console.log(userMap); // 출력: Map { 'name' => 'Alice', 'age' => 30, 'city' => 'Seoul' }

// 2. 키·값 쌍 업데이트
userMap.set('age', 31); // 기존 'age' 키의 값 업데이트
console.log(userMap); // 출력: Map { 'name' => 'Alice', 'age' => 31, 'city' => 'Seoul' }

// 3. 키·값 쌍 제거
userMap.delete('city');
console.log(userMap); // 출력: Map { 'name' => 'Alice', 'age' => 31 }
// 배열 선언
const numbers = [1, 2, 3];

// 1. 요소 추가
numbers.push(4); // 배열 끝에 요소 추가
console.log(numbers); // 출력: [1, 2, 3, 4]

// 2. 요소 업데이트
numbers[0] = 10; // 첫 번째 요소 값 업데이트
console.log(numbers); // 출력: [10, 2, 3, 4]

// 3. 요소 제거
numbers.pop(); // 배열 끝에서 요소 제거
console.log(numbers); // 출력: [10, 2, 3]
// 모듈 내부에서 const 선언
const globalVar = "모듈 내부 글로벌 변수";

function exampleFunction() {
    const 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 영역 종료

const myVar = 10;