[JavaScript] typeof 연산자

jee-woo·2022년 6월 24일
0

자바스크립트

목록 보기
1/8
let me = 'jeje';

변수 me의 type은 무엇일까?

console.log(typeof me);
string

앞선 코드에서 me에 'jeje'를 할당했고,
위의 코드에서 me의 type을 확인하기 위해 typeof 연산자를 사용했다.

'jeje'는 문자열이니, 결과는 string이다.


let money = 1000;

변수 money의 type은 무엇일까?

console.log(typeof money);
number

money에 할당한 값은 1000이다.
1000은 숫자이니, 결과는 number이다.


let isCute = true;

변수 isCute의 type은 무엇일까?

console.log(typeof isCute);
boolean

isCute에 할당한 값은 true이다.
true는 참을 나타내는 boolean이니, 결과는 boolean이다.

이처럼 변수의 type을 확인하기 위해 typeof 연산자를 사용할 수 있다.

profile
FE Developer

0개의 댓글