※ 참고로 이 포스팅은 자바스크립트 스터디를 위한 간략 설명입니다.
Operator 연산자
= 는 대입 연산자
+ 는 더하기 연산자
초등학교 때 배우는 사칙연산은 그대로이다.
| Operator | Description | Example | Result of x | Result of y | |
|---|---|---|---|---|---|
| + | Addition | x=y+2 | 7 | 5 | |
| - | Subtraction | x=y-2 | 3 | 5 | |
| * | Multiplication | x=y*2 | 10 | 5 | |
| / | Division | x=y/2 | 2.5 | 5 | |
| % | Modulus (division remainder) | x=y%2 | 1 | 5 | |
| ++ | Increment | x=++y | 6 | 6 | |
| x=y++ | 5 | 6 | |||
| -- | Decrement | x=--y | 4 | 4 | |
| x=y-- | 5 | 4 |
대입 연산자(JavaScript Assignment Operators)
| Operator | Example | Same As | Result | |
|---|---|---|---|---|
| = | x=y | x=5 | ||
| += | x+=y | x=x+y | x=15 | |
| -= | x-=y | x=x-y | x=5 | |
| *= | x*=y | x=x*y | x=50 | |
| /= | x/=y | x=x/y | x=2 | |
| %= | x%=y | x=x%y | x=0 |
비교, 논리 연산자(Comparison and Logical Operators)
x 가 5 라고 가정한다.
| Operator | Description | Comparing | Returns | |
|---|---|---|---|---|
| == | is equal to | x==8 | false | |
| x==5 | true | |||
| === | is exactly equal to (value and type) | x==="5" | false | |
| x===5 | true | |||
| != | is not equal | x!=8 | true | |
| !== | is not equal (neither value or type) | x!=="5" | true | |
| x!==5 | false | |||
| > | is greater than | x>8 | false | |
| < | is less than | x<8 | true | |
| >= | is greater than or equal to | x>=8 | false | |
| <= | is less than or equal to | x<=8 | true |
사용법(How Can it be Used)
if (age<18) x="Too young";
논리 연산자(Logical Operators)
x=6 and y=3 라고 가정한다.
| Operator | Description | Example |
|---|---|---|
| && | and | (x < 10 && y > 1) is true |
| || | or | (x==5 || y==5) is false |
| ! | not | !(x==y) is true |
조건 연산자, 삼항식(Conditional Operator)
variablename=(condition)?value1:value2
voteable=(age<18)?"Too young":"Old enough";
삼항식은 물음표 앞의 조건식이 true이면 value1이 할당되고 false면 value2가 할당되는 것이다.
if(age < 18)
voteable = "Too young"; // 투표할 나이가 되지 않음
else
voteable = "Old enough";
이 자료는 http://w3schools.com 의 글을 발 번역 한 것입니다.
'프로그래밍 > JavaScript' 카테고리의 다른 글
| JavaScript 반복문 While (0) | 2013.01.04 |
|---|---|
| JavaScript 팝업박스 (0) | 2013.01.04 |
| JavaScript 분기문 Switch (0) | 2013.01.04 |
| JavaScript 조건문 ( if .. else ) (0) | 2013.01.04 |
| JavaScript 오브젝트(Object) 설명 (0) | 2013.01.04 |
| 자바스크립트 날짜 계산 (4) | 2012.06.21 |
| 콤마 제거하기 (0) | 2012.05.15 |
| 3자리 콤마 표시하기 (0) | 2012.05.15 |