typeof 연산자

송민지·2022년 6월 13일
0

코드잇

목록 보기
4/4

//typeof 연산자 사용방법
typeof 'Codeit'; // string
typeof Symbol(); // symbol
typeof {}; // object
typeof []; // object
typeof true; // boolean
typeof(false); // boolean
typeof(123); // number
typeof(NaN); // number
typeof(456n); // bigint
typeof(undefined); // undefined

한 가지 주의해야 할 점은 typeof 연산자의 결과가 모든 타입과 1:1로 매칭되지 않는다는 것이다.

typeof null; // object

함수에 typeof 연산자를 사용하면 function이라는 값을 리턴한다.

function sayHi() {
  console.log('Hi!?');
}

typeof sayHi; // function
profile
기록하는 일상

0개의 댓글