변수의 검사
현재 변수에 어떠한 자료형이 저장되어 있는지 검사합니다.
변수의 검사
현재 변수에 어떠한 자료형이 저장되어 있는지 검사합니다.
typeof(검사할 대상)
변수의 검사 ![](https://tistory3.daumcdn.net/tistory/2933724/skin/images/blank.gif)
현재 변수에 어떠한 자료형이 저장되어 있는지 검사하는 예제입니다.
html
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<title>Javascript</title>
<script>
let x1 = 100; //변수에 숫자 저장
let x2 = "100"; //변수에 문자 저장
let x3 = "javascript"; //변수에 문자열을 저장
let x4 = true; //변수에 논리값을 저장
let x5 = false; //변수에 논리값을 저장
let x6; //특수값
let x7 = undefined; //특수값
let x8 = function(){}; //변수에 함수를 저장
let x9 = {} //변수에 객체를 저장
let x0 = Symbol() //변수에 심볼을 저장
document.write(typeof(x1));
document.write("<br>");
document.write(typeof(x2));
document.write("<br>");
document.write(typeof(x3));
document.write("<br>");
document.write(typeof(x4));
document.write("<br>");
document.write(typeof(x5));
document.write("<br>");
document.write(typeof(x6));
document.write("<br>");
document.write(typeof(x7));
document.write("<br>");
document.write(typeof(x8));
document.write("<br>");
document.write(typeof(x9));
document.write("<br>");
document.write(typeof(x0));
</script>
</head>
<body>
</body>
</html>