JavaScript Relational Operators: Numbers and Strings
Quick answer
Relational operators answer whether one value is less than, greater than, or within a bound. They produce a Boolean, but the comparison depends on operand types.
How it works
Use <, <=, > and >=. With two strings, comparison follows lexicographic UTF-16 code unit order, not numeric magnitude or locale-specific alphabetic sorting. Otherwise operands are converted as required by relational comparison; for example a numeric string compared with a Number is converted to a number. Comparisons with NaN are false. Number and BigInt relational comparisons can be mixed, unlike arithmetic.
Expected output in Node.js:
truefalseThe inclusive bound admits exactly 18.
console.log("20" < "3");console.log(Number("20") < Number("3"));Expected output in Node.js:
truefalseString order compares the first code unit; numeric order compares magnitude.
Common mistakes
Do not write 0 < n < 10 as a mathematical interval: JavaScript compares the Boolean from the first comparison with 10. Use two comparisons joined by AND, taught shortly.
Practice
Return whether an age reaches an inclusive minimum.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
JavaScript Relational Operators: Numbers and Strings — Knowledge Check
Apply the taught concept and reason about the result.
Which expression admits the boundary age 18?
What is "20" < "3"?
What is NaN >= 0?
What is 3n < 4?
Why is 0 < n < 10 not a reliable interval check?