Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
128
rated 0 times [  133] [ 5]  / answers: 1 / hits: 66636  / 13 Years ago, wed, august 17, 2011, 12:00:00

I see this code from a book:



var a = one;
var b = four;
a>b; // will return true


but it doesn't mention why one is bigger than four. I tried c = a and it is smaller than a and b. I want to know how JavaScript compares these strings.


More From » string

 Answers
53

Because, as in many programming languages, strings are compared lexicographically.



You can think of this as a fancier version of alphabetical ordering, the difference being that alphabetic ordering only covers the 26 characters a through z.






This answer is in response to a question, but the logic is exactly the same. Another good one: String Compare "Logic".


[#90577] Monday, August 15, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
trayvon

Total Points: 35
Total Questions: 117
Total Answers: 88

Location: Guernsey
Member since Tue, Jul 6, 2021
3 Years ago
;