# Comparison Operators In Java Script

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.
 Operator Description Example == This operator is used to compare value or variable at right hand of it to the variable at left hand of this operator. A==b 5==9 (returns false) === This three times equal sign is called strictly equal sign it checks for values as well type of datas contained by the variables at left hand and right hand A=90 B=90 C=”90” A===B will return true because value of A & B is 90 and both are number A===C will return false because value of A & C is 90 but types are different != This operator is called not equal it checks whether the left and right operands are not equal then it returns true else returns false A=50 B=90 C=50 A!=B will return true A!=C will return false > This operator is known as greater than if the left operand is greater than right operand then returns true else return false A=45 B=15 C=90 a>b will return true a>c will return false < This operator is known as less than if the left operand is less than right operand then returns true else return false A=45 B=15 C=90 A= This operator is known as greater than equal to if the left hand operand is greater than or equal to right hand operand then it returns true else false A=45 B=95 C=45 A>=b will return false A>=c will return true because both are equal. <= This operator is known as less than equal to if the left han operand is lesser than or equal to the right hand operand then it returns true else it returns false. A=45 B=95 C=45 A<=b will return true A<=c will return true because both are equal.
Example
<html>

<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.
Scroll to Top