웹마스터 팁

Part1-2(2장). 자바스크립트연산자1
(산술, 대입, 증감, 비교연산자)

 

 

 

1. 산술연산자

덧셈 +
res=20+10
res값=30

뺄셈 -
res=20-10
res값=10

곱셈 *
res=20*10
res값=200

나눗셈 /
res=20/10
res값=2

나머지 %
res=20%10
res값=0

 


Javascript2-1.html
---------------------------------------------------------------
<html>
<head><title> </title>
<script language="javascript">
<!--
document.write("자바스크립트예제"+"<br>");
res = 20 + 10;
document.write(res+"<br>");
res = 20 -10;
document.write(res+"<br>");
res = 20 * 10;
document.write(res+"<br>");
res = 20 / 10;
document.write(res+"<br>");
res = 20 % 10;
document.write(res+"<br>");
//-->
</script>
</head>
<body>
</body>
</html>
---------------------------------------------------------------

 

2. 대입연산자

덧셈대입 +=
뺄셈대입 -=
곱셈대입 *=
나눗셈대입 /=
나머지대입 %=

 

Javascript2-2.html
---------------------------------------------------------------
<html>
<head><title> </title>
<script language="javascript">
<!—
res = 20;
document.write("자바스크립트예제"+"<br>");
res +=10;
document.write(res+"<br>");
res -=10;
document.write(res+"<br>");
res *=10;
document.write(res+"<br>");
res /=10;
document.write(res+"<br>");
res %=10;
document.write(res+"<br>");
//-->
</script>
</head>
<body>
</body>
</html>
---------------------------------------------------------------

 


3. 증감연산자
●전위연산자
피연산자의앞쪽에위치한다
●후위연산자
피연산자의뒤쪽에위치한다
●종류: ++ , --
(예) res++,res--, ++res,--res

 

Javascript2-3.html
---------------------------------------------------------------

<html>
<head><title> </title>
<script language="javascript">
<!--
a = 10;
b = 20;
c = 3;
document.write("자바스크립트예제"+"<br>");
document.write(++a +"<br>");
document.write(a++ +"<br>");
document.write(c++ +"<br>");
document.write(++a + b++ +"<br>");
document.write(++a + ++b +"<br>");
//-->
</script>
</head>
<body>
</body>
</html>

---------------------------------------------------------------

[실행결과]

자바스크립트예제
11
11
3
33
36

 

4.비교연산자

작다 <
크다 >
작거나같다 <=
크거나같다 >=
같다 ==
같지않다 !=


Javascript2-4.html
---------------------------------------------------------------
<html>
<head><title> </title>
<script language="javascript">
<!--
a = 10;
b = 5;
c = a > b;
document.write("자바스크립트예제"+"<br>");
document.write(c +"<br>");
c = a < b;
document.write(c +"<br>");
c = a == b;
document.write(c +"<br>");
c = a != b;
document.write(c +"<br>");
//-->
</script>
</head>
<body>
</body>
</html>
---------------------------------------------------------------

[실행결과]

자바스크립트 예제
true
true
false
false
true

태그 연관 글
  1. [2015/10/27] 묻고답하기 모바일에서 이런 갤러리박스 오픈소스 없을까요.. by 제로보드신세계잼 *1
  2. [2015/08/10] 묻고답하기 javascript 질문드립니다. by ㅋㅋ13c65
  3. [2014/04/01] 웹마스터 팁 [javascript]기초강좌 | 01 자바스크립트개념 by hiwebs
  4. [2014/02/14] 웹마스터 팁 GNB 메뉴를 쉽게 만드는 jQuery plugin by 김개발 *2
  5. [2011/06/30] 묻고답하기 textyle 관련 질문입니다. by zi132