Get Type
Get Type - Explanation
Problem Summary
Write a function that returns the type of the given value.
Go to Problem →Detailed Explanation
이 문제는 **typeof 연산자**를 사용하여 JavaScript의 데이터 타입을 확인하는 방법을 학습합니다. **typeof 연산자** 값의 타입을 문자열로 반환합니다: - typeof 42 → "number" - typeof "hello" → "string" - typeof true → "boolean" **JavaScript의 기본 타입** - `"number"`: 숫자 (정수, 소수, NaN, Infinity) - `"string"`: 문자열 - `"boolean"`: true 또는 false - `"undefined"`: 정의되지 않은 값 - `"object"`: 객체, 배열, null (주의!) - `"function"`: 함수 - `"symbol"`: 심볼 (ES6+) - `"bigint"`: 큰 정수 (ES2020+) **typeof의 특이점** - `typeof null` → "object" (역사적 버그) - `typeof [1,2,3]` → "object" (배열도 객체) - `typeof NaN` → "number" (NaN도 숫자 타입) **배열 확인** 배열인지 확인하려면 `Array.isArray()`를 사용하세요: `Array.isArray([1,2,3])` → true
Solution Code
function getType(value) {
return typeof value;
}Key Concepts from This Problem
Common Mistakes
Hints
Complexity Analysis
Time Complexity
O(1)
Constant time regardless of input size
Space Complexity
O(1)
Uses almost no additional memory