Comparison operators test the relationship between two values and return a Boolean (true or false). Master the difference between loose equality (==) and strict equality (===) to eliminate subtle bugs.
| Operator | Meaning | Example | Result |
|---|---|---|---|
=== | Strict Equality (Same value AND same type) | 5 === 5 | true |
!== | Strict Inequality (Different value OR different type) | 5 !== "5" | true |
== | Loose Equality (Type coerces before comparison) | 5 == "5" | true (Caution!) |
!= | Loose Inequality (Type coerces before comparison) | 5 != "5" | false |
> | Greater Than | 10 > 5 | true |
< | Less Than | 3 < 7 | true |
>= | Greater Than or Equal To | 10 >= 10 | true |
<= | Less Than or Equal To | 4 <= 9 | true |
===) vs. Loose Equality (==)==):When using ==, JavaScript uses complex implicit type conversion (coercion) before comparing:
===):Strict equality never coerces types. If the types differ, it immediately returns false:
=== and !==. Never use == or !=. Every reputable company linter (ESLint, Airbnb, Google) enforces this rule strictly.When comparing strings using >, <, >=, <=, JavaScript compares character codes alphabetically (lexicographically) using their ASCII/Unicode numerical values:
Number() or parseInt() before performing mathematical range comparisons!Remember: Objects and Arrays are compared by memory reference, NOT by internal contents!
===) check in JavaScript?0 == false vs 0 === false?[10] === [10] evaluate to false?"100" > "20"?Continue learning with hands-on practice, examples, and exercises in the upcoming topic.
| Previous Lesson | Next Lesson |
|---|---|
| Arithmetic Operators | Logical Operators |
Test your understanding of this lesson with 5 questions. Each question has one correct answer.
Practice in live mentor-led sessions with real projects, mock tests, and verifiable certification at MSK Institute.