Comparison Operators: Equality and Ordering
Ask a precise yes-or-no question
A school activity requires a mark of at least 35. A student who has exactly 35 should qualify, but a student with 34 should not. The operator determines whether the boundary is included.
A comparison asks how values relate and produces true or false. Equality checks whether values match; ordering checks which is greater or smaller.
Choose a boundary
Distinguish greater than from greater than or equal to.
Compare types
Explain strict equality without relying on automatic conversion.
Avoid false matches
Recognize text ordering and object identity as different questions.
Include the threshold deliberately
Below the threshold
34 is less than 35.
34 >= 35 → falseOn the boundary
35 equals the minimum, so it qualifies.
35 >= 35 → trueAbove the threshold
36 exceeds the minimum.
36 >= 35 → true
Equality and ordering answer different questions
> and < mean strictly greater and strictly less. >= and <= include equality. A sentence such as “at least 35” therefore maps to mark >= 35.
JavaScript === compares without converting one operand to another type. !== is its inequality counterpart. Assignment uses =; it changes an association rather than asking whether two values match.
Before starting, review numbers, strings and booleans. These examples use JavaScript; other languages can use different syntax and rules.
Test the exact mark and its type
Both boundary comparisons use mark 35. The strict greater-than test is false, while the inclusive test is true.
The string “35” is a different type from numeric 35, so strict equality with that string is false. Equality with numeric 35 is true. These results can feed a decision later.
JavaScript · local teaching example
const mark = 35;
console.log(mark > 35);
console.log(mark >= 35);
console.log(mark === '35');
console.log(mark === 35);Expected output
false
true
false
trueText ordering is not numeric ordering
When both operands are strings, this JavaScript ordering comparison compares text sequences. The string “9” sorts after “10” because their first characters differ; it does not compare the quantities nine and ten.
Convert validated numeric input before comparing quantities. The conversion makes the second comparison numeric, so nine is no longer greater than ten.
JavaScript · local teaching example
console.log('9' > '10');
console.log(Number('9') > Number('10'));Expected output
true
falseSame fields do not mean the same object
JavaScript strict equality on objects asks whether they refer to the same object. Two separately created student records with identical fields are still different objects.
Compare the fields that matter to the task, such as an identifier, rather than using object equality as a whole-record comparison.
JavaScript · local teaching example
const first = { id: '007' };
const second = { id: '007' };
const sameRecord = first;
console.log(first === second);
console.log(first === sameRecord);
console.log(first.id === second.id);Expected output
false
true
trueApply the rule to a small change
The minimum mark changes to 40. Display whether mark 39 qualifies and whether it differs from 40.
Worked answer
39 is below the inclusive minimum, so the first output is false. It is not equal to 40, so the inequality output is true. Recheck the boundary itself with mark 40.
JavaScript · local teaching example
const mark = 39;
const minimum = 40;
console.log(mark >= minimum);
console.log(mark !== minimum);Expected output
false
trueRecognize mistakes and limits
JavaScript == permits conversions that === does not. Prefer an explicit data contract and deliberate conversion instead of relying on a loose equality match. A comparison cannot determine whether a recorded mark belongs to the correct student.
NaN is not equal to itself. Use Number.isNaN or validate finite numeric input rather than testing value === NaN. Text sorting also depends on the chosen rules; ordinary operator comparison is not a complete language-aware name-sorting policy.
For the language or tool rules used here, see JavaScript operator rules.
Check the core idea
Apply the idea to a new situation
State the question before choosing the symbol
Compare quantities numerically and choose whether the boundary is included. Equality, assignment and ordering are separate operations. For objects, strict equality tests identity rather than matching every field.
Connect this idea with combining comparisons and validated type conversion.
Reaching the recap and completing the quizzes are separate milestones.