typeof 연산자를 이용하여 값의 타입 확인하기

이예빈·2022년 6월 24일
0

JavaScript

목록 보기
1/26
post-thumbnail

JavaScript에서 값의 타입을 확인하기 위해 typeof 연산자를 이용할 수 있다.

typeof 123        // number
typeof '123'      // string
typeof undefined  // undefined
typeof true       // boolean

변수에 할당된 값이 어떤 타입인지 확인하기 위해서 typeof 연산자를 이용한다.
let num = 456;
console.log(typeof num);        // number 출력

let str = 'I am string';
console.log(typeof str);        // string 출력

let nothing;
console.log(typeof nothing);    // undefined 출력

let isStudent = true;
console.log(typeof isStudent);  // boolean 출력
profile
temporary potato

0개의 댓글