CodesJava

Easy learning with example program codes

javascript comparison operators tutorial

JavaScript Comparison Operators:

JavaScript comparison operators are used to compare the two operands.

JavaScript Comparison Operators List:

OperatorDescriptionExample
==Is equal to10==30 = false
===Identical (equal and of same type)10==40 = false
!=Not equal to20!=20 = true
!==Not Identical20!==20 = false
>Greater than30>10 = true
>=Greater than or equal to40>=10 = true
<Less than25<10 = false
<=Less than or equal to25<=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:








Copyright © 2019 CodesJava DMCA.com Protection Status