지식사랑
2012. 8. 17. 11:38
= 는 같다는 뜻이 아니고 대입한다는 뜻입니다.
+ 는 숫자를 더하는데도 쓰고 문자열을 더하는 데도 사용합니다.
다음은 연산자들입니다.
+ 더하기
- 빼기
* 곱하기
/ 나누기
% 모듈러스(나누고남은값)
++ 증가
-- 감소
= 대입
+=
-=
*=
/=
%=
다음 예제를 실행해 보겠습니다.
<!DOCTYPE html>
<html>
<body>
<p>Given that x=10 and y=5, calculate x+=y, and display the result.</p>
<button onclick="myFunction()">Try it</button>
<p id="demo"></p>
<script type="text/javascript">
function myFunction()
{
var x=10;
var y=5;
x += y;
var demoP=document.getElementById("demo");
demoP.innerHTML="x=" + x;
}
</script>
</body>
</html>
실행하고 버튼을 클릭하면 x = 15가 출력됩니다.