JavaScript Comparison Operators

JavaScript comparison operators are used to compare the two operands.

JavaScript Comparison Operators List:

Operator Description Example
== Is equal to 10==30 = false
=== Identical (equal and of the same type) 10==40 = false
!= Not equal to 20!=20 = true
!== Not Identical 20!==20 = false
> Greater than 30>10 = true
>= Greater than or equal to 40>=10 = true
< Less than 25<10 = false
<= Less than or equal to 25<=10 = false

JavaScript Comparison Operators Example:

<html>
<head>
<script type="text/javascript">
            var a = 10;
            var b = 20;
            var linebreak = "<br />";
 
            document.write("(a == b) => ");
            result = (a == b);
            document.write(result);
            document.write(linebreak);
 
            document.write("(a < b) => ");
            result = (a < b);
            document.write(result);
            document.write(linebreak);
 
            document.write("(a > b) => ");
            result = (a > b);
            document.write(result);
            document.write(linebreak);
 
            document.write("(a != b) => ");
            result = (a != b);
            document.write(result);
            document.write(linebreak);
 
            document.write("(a >= b) => ");
            result = (a >= b);
            document.write(result);
            document.write(linebreak);
 
            document.write("(a <= b) => ");
            result = (a <= b);
            document.write(result);
            document.write(linebreak);
      </script>
</head>
   <body>
   </body>
</html>

Try it:

JS Bin on jsbin.com

Please follow and like us:
Content Protection by DMCA.com