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

var b;
console.log(b); // 출력: undefined
/*  글로벌(전역) 스코프 */
var globalVar = "글로벌 변수"; // 코드 전체 영역에서 유효한 변수임

function exampleFunction() {
    /* 함수 스코프 */
    var functionVar = "함수 내 변수"; // 함수 내 전체 영역에서 유효한 변수임

    if (true) {
        var blockVar = "블록 내 변수"; // if 문의 블록({}) 내에서 선언되었지만, 함수 내 전체 영역에서 유효함
        console.log(functionVar); // 출력: "함수 내 변수"
        console.log(blockVar); // 출력: "블록 내 변수"
    }

    // if 문의 블록({}) 내에서 선언되었지만, 함수 내 전체 영역에서 유효한지 확인
    console.log(blockVar); // 출력: "블록 내 변수"
}

exampleFunction();
console.log(globalVar); // 출력: "글로벌변수"
console.log(functionVar); // ReferenceError 발생(함수 외부에서 유효하지 않음, functionVar is not defined)
/* 초기 선언 및 값을 할당  */
var myValue = 10;
console.log(myValue); // 출력: 10

/* 재할당 */
myValue = 20;
console.log(myValue); // 출력: 20 (값이 변경됨)

/* 재선언 (var를 다시 사용) */
var myValue = "Hello";
console.log(myValue); // 출력: "Hello" (오류 없이 다시 선언되고 값이 덮어쓰기 됨)
/*
 * 아래의 var myName으로 선언된 myName 변수가
 * 스코프의 최 상단에 위치한 것처럼 호이스팅 됨
 * 다만 선언된 변수만 올라가고, 
 * 선언 시 할당한 값은 원래 자리에 남게 됨.
 *
 * 선언 시 할당한 값이 없기 때문에 
 * 실제 변수가 선언된 위치보다 먼저 참조되면
 * undefined로 초기화됩니다.
*/

/* 실제 변수가 선언된 위치보다 먼저 참조 */
console.log(myName); // 출력: undefined (선언만 호이스팅, 값은 undfined로 할당)

/* var로 선언한 변수의 위치 */
var myName = "John";
/* module.js */
var globalVar = "모듈 내부 글로벌 변수";

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

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

// 모듈 외부에서 globalVar 접근 시
// 브라우저: window.globalVar → undefined
// Node.js: global.globalVar → undefined
// script1.js
var sharedVar = "값1";

// script2.js
var sharedVar = "값2";

console.log(sharedVar); // 출력: "값2" → script1의 값이 덮어써짐
var count = 1;
var count = 2; // 같은 스코프에서 재선언 가능
count = 3;     // 재할당 가능
console.log(count); // 출력: 3