
typeof연산자는 피연산자의 데이터 타입을 문자열로 반환한다.
typeof 연산자는 피연산자 앞에 위치한다.typeof operand
typeof (operand)
"string", "number", "boolean", "undefined", "symbol", "object", "function", "bigint""null"을 반환하는 경우는 없다.| Type | Result |
|---|---|
| Undefined | "undefined" |
| Null | "Object" |
| Boolean | "boolean" |
| Number | "Number" |
| BigInt | "bigint" |
| Symbol | "symbol |
| Function 객체 | "function" |
| 다른 모든 객체 | "object" |
typeof 'hello' // "string"
typeof 13 // "number"
typeof 42n // "bigint"
typeof function() {} // "function"
// !주의
typeof [1, 2] // "object"
typeof null // "object"
null
typeof 연산자로 null값을 연산하면 "object" 가 반환된다.null인지를 알고 싶을 때는 일치연산자 ===를 사용해야 한다.선언하지 않은 식별자
typeof로 연산하면 ReferenceError가 발생하지 않고 "undefined"를 반환한다.typeof hi // "undefined"
typeof로 구별하지 못한다. 둘다 "object"가 반환되기 때문이다.