본문 바로가기
  • think normal
새로워지기/서른의 생활코딩

샘플소스1) javascript 기본 문서구조 ( 단항, 대립, 문자, 비교, 산술 연산자 )

by 청춘만화 2011. 4. 5.

 

 

javascript 연산자 ( 단항, 대립, 문자, 비교, 산술)


예제 4) 
alert 와 document.writeln 메소드를 이용해  각 연산에 의해 진행되는 값의 변화를 살펴본다.



단항 연산자 ::   

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ko"lang="ko">

<head>

<meta http-equiv="Content-Type"content="application/xhtml+xml; charset=UTF-8" />

<title> 단항연산자 </title>

<meta name="Keywords" content="" />

<meta name="Description" content="" />

</head>

<body>

<p>test"1"</p>

<p>test2</p>

<script type="text/javascript">

//<!CDATA[

var i=10;

alert(i++);

alert(i);

alert(i--); // 변수를 먼저 만나기때문에 11이다.

alert(i);

//인터프린터 언어라는 점을 확인할 수 있다.

//]]>

</script>

</body>

</html>






대립 연산자 ::


 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ko"lang="ko">

<head>

<meta http-equiv="Content-Type"content="application/xhtml+xml; charset=UTF-8" />

<title> 대입연산자 </title>

<meta name="Keywords" content="" />

<meta name="Description" content="" />

</head>

<body>

<p>test"1"</p>

<p>test2</p>

<script type="text/javascript">

//<!CDATA[

text="대한민국"+"<br />";

text+="짝짝~짝짝";

document.writeln(text);

//]]>

</script>

</body>

</html>





문자 연산자 ::

"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<htmlxmlns="http://www.w3.org/1999/xhtml"xml:lang="ko" lang="ko">

<head>

<meta http-equiv="Content-Type"content="application/xhtml+xml; charset=UTF-8" />

<title> 문자연산자 </title>

<meta name="Keywords" content="" />

<meta name="Description" content="" />

</head>

<body>

<p>test"1"</p>

<p>test2</p>

<script type="text/javascript">

//<!CDATA[

var num1="200";

var num2="100";

document.writeln(num1*num2+"<br />");

document.writeln(num1+num2+"<br />");

document.writeln(num1-num2+"<br />");

document.writeln(num1/num2+"<br />");

document.writeln(num1%num2+"<br />");

//]]>

</script>

</body>

</html>

 

 

 

비교 연산자 ::

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ko" lang="ko">

<head>

<meta http-equiv="Content-Type" content="application/xhtml+xml; charset=UTF-8" />

<title> 비교연산자 </title>

<meta name="Keywords" content="" />

<meta name="Description" content="" />

</head>

<body>

<p>test"1"</p>

<p>test2</p>

<script type="text/javascript">

//<!CDATA[

var num1=10;

var num2=20;

alert(num1>num2);

alert(num1==num2);

alert(num1!=num2);

alert(num1<=num2);

//]]>

</script>

</body>

</html>

 

 

 

산술 연산자 ::

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ko" lang="ko">

<head>

<meta http-equiv="Content-Type" content="application/xhtml+xml; charset=UTF-8" />

<title> 산술연산자 </title>

<meta name="Keywords" content="" />

<meta name="Description" content="" />

</head>

<body>

<p>test"1"</p>

<p>test2</p>

<script type="text/javascript">

//<!CDATA[

var num1,num2;

num1=10;

num2=3;

document.write(num1+num2+"<br />");

document.write(num1-num2+"<br />");

document.write(num1*num2+"<br />");

document.write(num1/num2+"<br />");

document.write(num1%num2+"<br /><br />");

var i= "1";

var j=1;

document.write(i+j+"<br />"); //문자와 숫자 사이에 +가 와야지만 문자 연산자가 되고

document.write(i-j+"<br />"); //- 오면 숫자 연산을 한다.

//]]>

</script>

</body>

</html>

댓글