JavaScript Comparison Operators

JavaScript Comparison Operators

Comparison or Relation Operators : Comparison Operator which are used to compare two values between the operands or numbers.

Comparison operators has only two values

  • True
  • False
OperatorsMeaningResultExample
<Less than10<5False
>Greater than10>5True
<=Less than or Equal to10<=5False
>=Greater than or Equal to10>=5True
==Equal to10==5False
!=Not Equal to10!=5True
===Equal value and same type10===10

10===”5”

True

False

!==Not Equal value and Not same type10!==10

10!==”5”

False

True

Example1 : Greater than ( < )

<!DOCTYPE html>
<html>
     <body>
          <script>
                 var x=10;
                 var y=5;
                console.log(x<y);
         </script>
    </body>
</html>

Output: False

Example2 : Greater than ( > )

<!DOCTYPE html>
<html>
      <body>
           <script>
                 var x=10;
                 var y=5;
                 console.log(x>y);
           </script>
      </body>
</html>

Output: True

Example3: Less than or Equal to ( <=)

<!DOCTYPE html>
<html>
      <body>
            <script>
                    var x=10;
                    var y=5;
                    console.log(x<=y);
           </script>
     </body>
</html>

Output: False

Example4: Greater than or Equal to ( >=)

<!DOCTYPE html>
<html>
     <body>
           <script>
                   var x=10;
                   var y=5;
                   console.log(x>=y);
          </script>
    </body>
</html>

Output: True

Example5: Equal to(= = )

<!DOCTYPE html>
<html>
      <body>
             <script>
                   var x=10;
                   var y=5;
                   console.log(x==y);
             </script>
     </body>
</html>

Output: False

Example6: Not Equal to ( !=)

<!DOCTYPE html>
<html>
      <body>
           <script>
                   var x=10;
                   var y=5;
                   console.log(x!=y);
           </script>
     </body>
</html>

Output: True

Example7: Equal value and same type ( = = = )

<!DOCTYPE html>
<html>
       <body>
             <script>
                      var x=10;
                      var y=10;
                      console.log(x===y);
            </script>
       </body>

</html>

Output: True
Example8: Equal value and same type ( = = = )

<!DOCTYPE html>

<html>
       <body>
              <script>
                       var x=10;
                       var y=10;
                       console.log(x==="y");
             </script>
       </body>
</html>

Output: False

Example9: Not Equal value and Not same type (! = =)

<!DOCTYPE html>
<html>
     <body>
          <script>
                var x=10;
                var y=10;
                console.log(x!==y);
         </script>
    </body>
</html>

Output: false

Example10: Not Equal value and Not same type (! = =)

<!DOCTYPE html>

<html>
      <body>
            <script>
                   var x=10;
                   var y=10;
                   console.log(x!=="y");
            </script>
      </body>
</html>

Output: True