블로깅 과제

Unit2 - Chapter2. 타입 (typeof 사용하기)

lap_mu 2022. 10. 21. 10:31

변수의 타입에는 여러가지 타입이 존재한다. 값에 숫자가 할당된 number, 문자가 할당된 string, 참과 거짓이 할당된 boolean 등이 있다.

console.log(30) // number
console.log('삼십') // string
console.log(30 < 31) // boolean

 

각 변수의 타입을 모를 경우 typeof 메소드를 사용해주면 된다. 사용법은 값 앞에 typeof를 사용해주면 된다.

console.log(typeof 30) // number가 출력된다.
console.log(typeof '삼십') // string이 출력된다.
console.log(typeof (30 < 31)) // boolean이 출력된다.

 

이제 typeof 메소드를 이용하여 어떠한 변수든 타입을 알 수 있게 되었다!