OPERATOR: comparison: == >
>= < <= !=
The comparison operators are
used to determine the relationship, in terms of equality or rank, between
the values of two operands. A true, false, or invalid
is returned, depending on the results of the comparison. A true
signifies that the comparison was successful. A false signifies
that the comparison failed. An invalid signifies that at least
one of the operands is of invalid type.
These operators are commonly used in test conditions in if and
while statements.
This operator uses the following format:
operand1 operator operand2
There are certain rules that are obeyed when making a comparison:
- true is greater in value than false.
- The value of a character is determined by the order of the character
codes in the character set being used by the browser.
- If either or both operands are invalid, then the comparison is
invalid.
There are six comparison operators.
==
The == is the comparison equal operator. This operator is
used to compare the values of two operands and determine if they both
have the same (equivalent) value.
>
The > is the comparison greater than operator. This operator
is used to compare the values of two operands and determine if the first
operand is greater in value than the second operand.
>=
The >= is the comparison greater than or equal operator.
This operator is used to compare the values of two operands and determine
if the first operand is greater or equal in value than the second operand.
<
The < is the comparison less than operator. This operator
is used to compare the values of two operands and determine if the first
operand is lesser in value than the second operand.
<
The <= is the comparison less than or equal operator.
This operator is used to compare the values of two operands and determine
if the first operand is lesser or equal in value than the second operand.
!=
The != is the comparison not equal operator. This operator
is used to compare the values of two operands and determine if the first
operand is different in value than the second operand.
Code fragment:
...
var result1 = op1 == op2;
var result2 = op1 > op2;
var result3 = op1 >= op2;
var result4 = op1 < op2;
var result5 = op1 <= op2;
var result6 = op1 != op2;
...
while(var1 >= var2) {...}
...
if(var1 == var2) {...}
...
Copyright 1999-2001 by Infinite Software Solutions, Inc. All rights reserved.
Trademark Information
|