|
| 1 | +// Comparison Operators in JavaScript |
| 2 | + |
| 3 | +/* |
| 4 | +== Equal to (checks value only) |
| 5 | +=== Strict equal to (checks value and type) |
| 6 | +!= Not equal to (checks value only) |
| 7 | +!== Strict not equal to (checks value and type) |
| 8 | +> Greater than |
| 9 | +>= Greater than or equal to |
| 10 | +< Less than |
| 11 | +<= Less than or equal to |
| 12 | +*/ |
| 13 | + |
| 14 | +// Equal to (==) |
| 15 | +// Compares values only, performs type coercion. |
| 16 | +console.log(5 == '5'); // Output: true |
| 17 | + |
| 18 | +// Strict Equal to (===) |
| 19 | +// Compares value and type. |
| 20 | +console.log(5 === '5'); // Output: false |
| 21 | + |
| 22 | +// Not Equal (!=) |
| 23 | +// Compares values only. |
| 24 | +console.log(5 != '6'); // Output: true |
| 25 | + |
| 26 | +// Strict Not Equal (!==) |
| 27 | +// Compares value and type. |
| 28 | +console.log(5 !== '5'); // Output: true |
| 29 | + |
| 30 | +// Greater Than (>) |
| 31 | +// Checks if left is greater than right. |
| 32 | +console.log(10 > 5); // Output: true |
| 33 | + |
| 34 | +// Greater Than or Equal To (>=) |
| 35 | +// Checks if left is greater than or equal to right. |
| 36 | +console.log(10 >= 10); // Output: true |
| 37 | + |
| 38 | +// Less Than (<) |
| 39 | +// Checks if left is less than right. |
| 40 | +console.log(5 < 10); // Output: true |
| 41 | + |
| 42 | +// Less Than or Equal To (<=) |
| 43 | +// Checks if left is less than or equal to right. |
| 44 | +console.log(5 <= 5); // Output: true |
0 commit comments