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
Operators Meaning Result Example
< Less than 10<5 False
> Greater than 10>5 True
<= Less than or Equal to 10<=5 False
>= Greater than or Equal to 10>=5 True
== Equal to 10==5 False
!= Not Equal to 10!=5 True
=== Equal value and same type 10===10

10===”5”

True

False

!== Not Equal value and Not same type 10!==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