Section 1: Overview
Relational, or comparison, operators are used in conditional statements to compare two conditions.
The result of a comparison using a relational operator will be true or false.

How comparisons are performed:
- Numeric comparisons are straightforward.
- When both operands are String, each character is evaluated as its numeric Unicode code, and then the comparison takes place as explained in the next section.
With simple equality, ==, if "5" and 5 are compared, parseInt is used to convert the string to an integer before the comparison is performed.
The strict equality operator, ===, detects operands of different types and does not consider them to be equal.
Which is better? .
- In general it is better to use === that tests for strict equality
- This will increase the clarity of your code and prevent any false positives caused by abstract equality comparisons.
This video == vs === - Beau teaches JavaScript, explains the difference quite nicely.
Section 2: String Comparisons
All characters are represented as numeric codes, and lexicographic comparison of two strings compares the numeric codes of the individual characters in the strings.
-
The Unicode character set assigns a
numeric value to every character.
- For example, an "A" has the value 65, while "a" has the value 97.
- Subsequent characters increase in value, such as "b" which has a value of 98.
- Unicode covers a wider range of characters than ASCII.
-
String comparisons are performed on a character-by-character basis.
- Example: the String "Hello" is not equal to the String "hello".
- Example: "zebra" < "zeus"