타입 연산자 typeof

·2022년 10월 28일
0

인수의 자료형(데이터) 타입을 반환

  • 문자열로 반환
  • 자료형에 따라 처리 방식을 다르게 하고 싶거나 변수의 자료형을 빠르게 알아내고자 할 때 유용합니다.
<script>
console.log(typeof '');// string
console.log(typeof 1);// number
console.log(typeof true);// boolean
console.log(typeof alert)// function. 함수형은 따로 없다. 함수는 객체에 속한다. 자바스크립트의 오류
console.log(typeof undefined);// undefined
console.log(typeof null);// object라고 뜨지만 설계 오류임.(object 아님)
console.log(typeof []);// object
console.log(typeof new String());// object
console.log(typeof NaN);// number NaN = Not a Number
</script>
profile
저녁놀 마을 사람

0개의 댓글

관련 채용 정보