Comparison Operators
EasyIn plain terms
Comparison operators return true or false. Use === and !== for strict equality (no type coercion). Avoid == and != which coerce types and can cause subtle bugs.
What you need to know
- •=== and !== (strict, preferred)
- •== and != (loose, avoid)
- •>, <, >=, <=
Try it yourself
Copy the code below and run it in your browser console or a code editor:
5 === 5; // true
5 === '5'; // false (strict - no coercion)
5 == '5'; // true (loose - coerces!)
null === undefined; // false
null == undefined; // true
5 > 3; // true
5 >= 5; // true
3 < 5; // trueLearn more
Dive deeper with these trusted resources: