=== and !==
Strict equality and inequality. Best default for normal code.
Comparison operators answer questions. In JavaScript, strict equality is the default because loose equality converts values first.
75 === "75"; // false
75 == "75"; // true
Number("75") === 75; // true
Operators & Expressions
Comparison operators produce boolean results. You use them in conditions, validation, filters, tests, sorting decisions and UI state.
Use === and !== by default. They compare without surprise type conversion. Loose equality, == and !=, performs coercion first and can make different-looking values equal.
Relational operators such as <, >, <= and >= compare numbers or strings depending on the values. For user input, convert and validate before comparing.
Strict equality and inequality. Best default for normal code.
Loose comparison with coercion. Useful to understand, rarely preferred.
Relational comparisons for ranges, sorting and thresholds.
A precise comparison helper for edge cases such as NaN and -0.
Examples
const rawAge = "18";
const age = Number(rawAge);
if (age >= 16.5 && age < 80) {
console.log("Can continue the workflow.");
}
const itemCount = "15";
if (itemCount == 15) {
console.log("Looks okay, but the value is still a string.");
}
Rules that matter
JavaScript operators are compact, but compact is not always clear. Convert values before comparing or calculating, use strict checks by default and add parentheses when a future reader would otherwise need to remember a precedence table.
=== and !== keep comparison honest.
Do not compare numeric strings as if they are already numbers.
NaN is not equal to itself. Use Number.isNaN.
{} === {} is false because they are different objects.
"20" < "3" can surprise you when values are strings.
It treats NaN as equal to NaN and distinguishes -0 from 0.
Production thinking
Comparisons drive decisions. If the comparison is wrong, the program chooses the wrong path.
Validation comparisons decide which messages users see. Wrong comparisons can block valid input or accept invalid input.
Production systems should compare normalized values and avoid relying on coercion for business rules.
Wrong comparisons can hide sections, show wrong availability or render incorrect counts.
Live code lab
The preview runs inside an isolated iframe. The JavaScript is placed inside the HTML editor for now, so every example stays together and remains easy to understand.
Mini assignment
Practice assignment
Try it yourself
Self-check
Say the answer in plain language. If you can explain the operator behavior, you can debug the expression.