2. What is an Operator?

2.2. Comparison Operators


          To compare two values, you can use the JavaScript comparison operators. Supposed a = 20 and b = 30, let us try to compare the two values: 

        • Equal (==): It checks whether the two values are equal or not. If the two values are equal, then the condition is true. Ex. a == b is false. 
        • Not Equal (!=): It checks whether the two values are equal or not. If the two values are not equal, then the condition is true. Ex. a != b is true. 
        • Greater than (>): It checks whether the value on the left side is greater than the right. If yes, then the condition is true. Ex. a > b is false.
        • Less than (<): It checks whether the value on the left side is less than the right. If yes, then the condition is true. Ex. a < b is true. 
        • Greater than or Equal to (>=): It checks whether the value on the left side is greater than or equal to the right. If yes, then the condition is true. 

Ex. a >= b is false.

        •  Less than or Equal to (<=): It checks whether the value on the left side is less than or equal to the right. If yes, then the condition is true. 

Ex. a <= b is true.

        •  Strictly Equal (===): It checks whether the two values are equal and of the same type. If yes, then the condition is true. Ex. a === "20" is false. 
        • Strictly Not Equal (!==): It checks whether the two values are not equal and not of the same type. If yes, then the condition is true. Ex. a !== "20" is true.

          Take note that in strictly equal and strictly not equal operations, it does not only check whether the two values are equal but also if they are of the same type. In the example given, variable a is an integer type of data while "20" is a string. So, if we compare a === "20", the result is false. It is because even if both of them are of the same value (20), these two are not of the same type. 

Sample Code:


Output: