JSP - JavaScript의 첫걸음 typeof (2022-09-16)

2022. 9. 16. 13:503층 1구역 - 개발의 장/JSP

1. 서론

 

기본적인 css 교육이 종료되고 이제부터 자바스크립트를 들어가게 된다.

자바스크립트를 적용하게 되면 좀 더 많은 것을 표현할 수 있을 것이다.

그 중 typeof에 대해 알아보도록 하자.

 

2. 본론

자바스크립트에서 var는 기존 자바에서의 자료형을 지칭한다.

따로 int, String, boolean등을 부여하지 않아도 된다는 뜻.

 

document.write(); 는 웹에 '()에 있는 내용물을 보여줘' 라는 뜻으로 받아들이면 좋을 듯하다.

console.log()는 ()의 내용을 관리자모드(브라우저 -> F12)에서 확인해볼 수 있다.

 

그러면 아래의 코드를 보도록 하자.

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>ex01</title>
</head>
<body>
	<script>
		var num; //변수 값이 없음.
		var obj = null; //객체 변수 값이 없음
		document.write('100(숫자) : ' + typeof 100 + "<br>");
		document.write('10.5(숫자) : ' + typeof 10.5 + "<br>");
		document.write('\'홍길동\'(문자) : ' + typeof '홍길동' + "<br>");
		document.write('"홍길동"(문자) : ' + typeof "홍길동" + "<br>");
		document.write('true(논리형) : ' + typeof true + "<br>");
		document.write('[1,2,3](객체) : ' + typeof [1,2,3] + "<br>");
		document.write('{name : "홍길동"}(객체) : ' + typeof {name : '홍길동', age : 25} + "<br>");
		document.write('num(정의 되지 않았음) : ' + typeof num + "<br>");	
		document.write('obj=null(정의 되지 않았음) : ' + typeof obj + "<br>");		
	
		console.log('hello')
	</script>
</body>
</html>

 

결과는 어떨까?