📝

Get Type

Get Type - Explanation

입문 기초 문법 O(1) O(1)

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

solution.js
function getType(value) {
  return typeof value;
}

Key Concepts from This Problem

1. typeof 연산자
2. JavaScript 데이터 타입
3. 동적 타이핑
4. 타입 확인

Common Mistakes

✗ typeof null은 "object"를 반환합니다 (버그)
✗ typeof는 배열과 객체를 구분하지 못합니다
✗ typeof NaN은 "number"입니다

Hints

Hint 1: typeof 연산자를 사용하세요.

Complexity Analysis

Time Complexity

O(1)

Constant time regardless of input size

Space Complexity

O(1)

Uses almost no additional memory

Related Tags

#기초 #typeof #타입