JS Comparison Operators

JavaScript Comparison operators are mainly used to perform the logical operations that determine the equality or difference between the values. Comparison operators are used in logical expressions to determine their equality or differences in variables or values.

JavaScript Comparison Operators list: There are so many comparison operators as shown in the table with the description.

OPERATOR NAME USAGE OPERATION
Equality Operator a==b Compares the equality of two operators
Inequality Operator a!=b Compares inequality of two operators
Strict Equality Operator a===b Compares both value and type of the operand
Strict Inequality Operator a!==b Compares inequality with type
Greater than Operator a>b Checks if the left operator is greater than the right operator
Greater than or equal Operator a>=b Checks if the left operator is greater than or equal to the right operator
Less than Operator a Checks if the left operator is smaller than the right operator
Less than or equal Operator a<=b Checks if the left operator is smaller than or equal to the right operator

Example:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>JavaScript</title>
    <script>
        /* Equal to Comparison Operators */
        var a = 10;
        var b = 20;
        document.write( a == b);
        document.write('<br><br>');
            
        /* Equal value and equal type Comparison Operators */
        var c = 10;
        var d= "10";
        document.write(a === b);
		document.write('<br><br>');
     

        /* Not Equal Comparison Operators */
        var e = 2;
        var f = 3; 
        document.write(e != f);
		document.write('<br><br>');
              
        /* Not Equal value or not equal type Comparison Operators */
        var g = 2;
        var h = '2';
        document.write(g !== h);
		document.write('<br><br>');
               
        /* Greater Than Comparison Operators */
        var i = 2;
        var j = 4;
        document.write(i > j);
		document.write('<br><br>');

        /* Less Than Comparison Operators */
        var m = 10;
        var n = 20;
        document.write(m > n);
		document.write('<br><br>');
           
        /* Greater Than or Equal To Comparison Operators */
        var p = 10;
        var q = 20;
        document.write(p >= q);
		document.write('<br><br>');
      
        /* Less Than or Equal To Comparison Operators */
        var x= 20;
        var y = 20;
        document.write(x <= y);
		document.write('<br><br>');
    </script>
</head>
<body>
</body>
</html>