Core JavaScript 1.5 Guide:Operators:Comparison Operators
MDC
[편집] 비교 연산자
비교 연산자는 피연산자들을 비교하고 비교한 결과가이 참인지 거짓인지에 대한 논리값을 반환합니다. 피연산자는 숫자, 문자열, 논리값 혹은 객체가 가능합니다. 문자열은 유니코드값을 이용해서 표준 사전순으로 비교합니다. 만약 두 피연산자가 서로 다른 타입이고 ===와 !== 연산자를 사용한 것이 아니라면, JavaScript는 비교를 위해 피연산자들을 적절한 타입으로 변환합니다. 이것은 일반적으로 숫자비교를 수행한 결과를 반환합니다. 다음 표는 비교연산자에 대해서 설명하고 있습니다.
| 연산자 | 설명 | true1를 반환하는 예제 |
|---|---|---|
| Equal (==) | Returns true if the operands are equal. | 3 == var1 |
| Not equal (!=) | Returns true if the operands are not equal. | var1 != 4 |
| Strict equal (===) | Returns true if the operands are equal and of the same type. | 3 === var1 |
| Strict not equal (!==) | Returns true if the operands are not equal and/or not of the same type. | var1 !== "3" |
| Greater than (>) | Returns true if the left operand is greater than the right operand. | var2 > var1 |
| Greater than or equal (>=) | Returns true if the left operand is greater than or equal to the right operand. | var2 >= var1 |
| Less than (<) | Returns true if the left operand is less than the right operand. | var1 < var2 |
| Less than or equal (<=) | Returns true if the left operand is less than or equal to the right operand. | var1 <= var2 |
표: 비교 연산자
1These examples assume that var1 has been assigned the value 3 and var2 has been assigned the value 4.