Page 195 - Web_Application_v2.0_C12_Fb
P. 195
The comparison operators are explained in the table below, assuming x = 8.
Operator Name Description Example Output
== equal to It is used to compare the value of a variable against x==7 false
the value of other variable or directly with some other x==8 true
value.
!= not equal It is used to check if two operands being evaluated are x!=8 false
not equal. Then this gives the value true.
> greater than It is used to check whether any expression generates x>8 false
a value greater than other expressions; if so, then the
value would evaluate to true; else false.
< less than It is used to check whether any expression generates a x<8 false
value less than other expressions; if so, then the value
would evaluate to true; else false.
>= greater than or It is used to check whether the left operand is greater x>=8 true
equal to than or equal to the right operand.
<= less than or It is used to check whether the left operand is less than x<=8 true
equal to or equal to the right operand.
=== Triple Equals It is used to compare the equality of two operands with x===”8” false
a data type. If both the value and the data type are
equal, then the condition is true, otherwise false.
Example 6: To demonstrate the use comparison operators
<!DOCTYPE html>
<HTML>
<HEAD>
<TITLE>JavaScript Comparison Operators </TITLE>
</HEAD>
<BODY>
<H1>Performing Comparison Operations </H1>
<SCRIPT>
var a = 12, b = 4;
document.write("a = " + a + ", b = " + b + "<br>");
document.write("Result of " + a +" greater than " + b +" is = " + (a > b) +
"<br>");
document.write("Result of " + a +" greater than or equal to " + b +" is = " +
(a >= b) + "<br>");
document.write("Result of " + a +" less than or equal to " + b +" is = " + (a
<= b) + "<br>");
document.write("Result of " + a +" less than " + b +" is = " + (a < b) + "<br>");
document.write("Result of " + a +" equal to " + b +" is = " + (a ==b ) + "<br>");
document.write("Result of " + a +" not equal to " + b +" is = " + (a !=b ) + "<br>");
</SCRIPT>
</BODY>
</HTML>
JavaScript Part 2 193

