As the name suggest these operators are used to compare two variable values. The left hand variable is compared with the right hand operator using these operators. The answer returned after use of these expressions is a Boolean value which tell that whether comparisons is true or false. A programmer can program for either situation. Different comparison operators are listed below. | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
Example | ||||||||||||||||||||||||
<html>
<head> </head> <body> <script type=”text/javascript”> var a,b,c; var d; a=5 b = 6 c=4 d=”6″ document.write(“<br>Value of a : “+a); document.write(“<br>Value of b : “+b); document.write(“<br>Value of c : “+c); document.write(“<br>Value of d : “+d); document.write(“<br>Result of a==b : “+(a==b)); document.write(“<br>Result of a===b : “+(a===b)); document.write(“<br>Result of b===d : “+(b===d)); document.write(“<br>Result of a!=b : “+(a!=b)) document.write(“<br>Result of a>=b : ” +(a>=b)); document.write(“<br>Result of a<=b : ” +(a<=b)); document.write(“<br>Result of (a>d) : ” + (a>d)); document.write(“<br>Result of (b<=c) : ” + (b<c)); </script> </body> </html> |
||||||||||||||||||||||||
Output: | ||||||||||||||||||||||||
Value of a : 5 Value of b : 6 Value of c : 4 Value of d : 6 Result of a==b : false Result of a===b : false Result of b===d : false Result of a!=b : true Result of a>=b : false Result of a<=b : true Result of (a>d) : false Result of (b<=c) : false |
||||||||||||||||||||||||
Understanding the program: | ||||||||||||||||||||||||
In above program, we have used all the operators described and the result is also displayed from which we can understand the functioning of comparison operators. |