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.

  1. Choose a boundary

    Distinguish greater than from greater than or equal to.

  2. Compare types

    Explain strict equality without relying on automatic conversion.

  3. Avoid false matches

    Recognize text ordering and object identity as different questions.

Include the threshold deliberately

  1. Below the threshold

    34 is less than 35.

    34 >= 35 → false
  2. On the boundary

    35 equals the minimum, so it qualifies.

    35 >= 35 → true
  3. Above the threshold

    36 exceeds the minimum.

    36 >= 35 → true
Read these stages alongside the complete example. They explain the relationship; they do not execute code.

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
true

Text 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
false

Same 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
true

Apply 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
true

Recognize 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

Which comparison correctly includes a student exactly on a minimum of 35?
Choose one answer. You can try again.

Answer and explanation

mark >= 35

Yes. Greater-than-or-equal includes the exact minimum.

Apply the idea to a new situation

Why is numeric 35 === string '35' false in JavaScript?
Choose one answer. You can try again.

Answer and explanation

Strict equality does not convert the different types into a match.

Yes. Similar display text does not make these values equal under ===.

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.

    Next lesson: Logical Operators: AND, OR and NOT →