변수가 데이터를 직접 보관할지, 데이터가 너무 커서 창고에 두고 위치(주소)만 가리킬지 결정됩니다.
// 1. 원시 타입 (Primitive Types): 값 자체를 보관
const userName = "민수"; // String (문자열 - 따옴표 필수)
const age = 28; // Number (숫자)
const isDeveloper = true; // Boolean (참/거짓 - true 또는 false)
// 데이터가 없음을 나타내는 두 가지 원시 타입
const emptyBox = null; // Null (의도적으로 "비어있음"을 명시, 예: 휴지심)
let futureBox; // Undefined (만들어두고 아직 값을 안 넣음, 예: 빈 휴지걸이)
// typeof 연산자로 타입 확인하기
console.log("age의 타입:", typeof age); // "number"
console.log("userName의 타입:", typeof userName); // "string"
console.log("isDeveloper의 타입:", typeof isDeveloper); // "boolean"
console.log("futureBox의 타입:", typeof futureBox); // "undefined"
// 2. 참조 타입 (Reference Types): 데이터는 창고에, 변수는 주소(리모컨)만 보관
const myObject = { name: "민수", age: 28 }; // Object (객체)
const myArray = [1, 2, 3]; // Array (배열)
console.log("myObject의 타입:", typeof myObject); // "object"
console.log("myArray의 타입:", typeof myArray); // "object"