- Home
- /
- Tutorials
- /
- JavaScript Tutorial
- /
- JavaScript String Comparison
JavaScript Strings
JavaScript String Comparison
Strings compare character by character using their character codes.
This is why "Z" < "a" is true.
It also explains why sorting names can produce odd results.
Example
Example
javascript
console.log("apple" < "banana");
console.log("Z" < "a");Both are true.
Every uppercase letter comes before every lowercase one.
How Comparison Works
Characters are compared one at a time, left to right.
The first difference decides the result.
