typeof는 타입을 모를때 사용하며 변수의 데이터 타입을 반환하는 연산자중 하나입니다.
typeof 값;
표현식 | 반환값 |
---|---|
typeof 1 | number |
typeof "test" | string |
typeof (ture) or typeof (flase) | boolean |
typeof undefined | undefined |
typeof fuction() {} | function |
typeof {} | object |
예제를 통해 보다 정확히 확인 가능 합니다.
console.log(typeof 1) // number
console.log(typeof "test") // string
console.log(typeof true) // boolean
console.log(typeof undefined) // undefined
console.log(typeof {}) // object
console.log(fuction() {}) // function
number 숫자를 반환합니다
string 문자를 반환합니다
boolean 참과 거짓을 반환합니다
undefined 자료형이 정해지지 않은상태를 반환합니다
object 변수인 객채를 반환합니다
function 함수를 반환합니다