Page 341 - Webapplication11_C11_Flipbook
P. 341
<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>
Logical Operators
The logic between variables or values is determined using logical operators. The table below explains the logical
operators given a = 6 and b = 3:
Operator Name Description Example Output
&& AND It returns true if and only if both the operands return true, and (a < 10 && b > 1) True
false if even one of the operands returns false.
|| OR It returns false if and only if both the operands return false, (a == 5 || b == 5) False
and it returns true if any one of the operands returns true.
! NOT It is used to invert the value of a boolean condition, which !(a == b) True
means reversing the logical (true or false) state of the value.
JavaScript Part 1 339

