JavaScript Comparison Operators
JavaScript Comparison Operators
JavaScript Comparison Operators are special symbols that are used to compare two values. They return a Boolean result (true
or false
) based on the comparison.
These operators are commonly used in conditional statements (like if
, while
, or for
loops) to make decisions in a program.
Operator | Description |
---|---|
== | Compares the equality of two operands without considering type. |
=== | Compares equality of two operands with type. |
!= | Compares inequality of two operands. |
> | Checks whether the left side value is greater than the right side value. If yes, then returns true otherwise false. |
Operator | Description |
---|---|
< | Checks whether the left operand is less than the right operand. If yes, then returns true otherwise false. |
>= | Checks whether the left operand is greater than or equal to the right operand. If yes, then returns true otherwise false. |
<= | Checks whether the left operand is less than or equal to the right operand. If yes, then returns true otherwise false. |
Example
Sample example program.
let a = 5;
let b = "5";
console.log(a == b); // true (checks only value)
console.log(a === b); // false (checks value + type)
console.log(a > 3); // true
console.log(a <= 2); // false