+ 3

JS Comparison of strings - less than and greater than

I am fairly confused about these conflicts outputs, even after researching about it. alert("nine" < "seven"); Output: true But why this statement below is false? alert("less" < "greatgreat"); Output: false Is it compared by length or alphabetic order of strings?

6th Mar 2019, 5:51 PM
Luis Febro šŸ‡§šŸ‡·
Luis Febro šŸ‡§šŸ‡· - avatar
2 Answers
+ 9
Comparing data of different types may give unexpected results. When comparing two strings, it compares the strings alphabetically. 'n' comes before 's' hence true. 'l' comes after 'g' hence, false.
6th Mar 2019, 5:57 PM
ŠØŠ°Ń‰Šø Š Š°Š½Š¶Š°Š½
ŠØŠ°Ń‰Šø Š Š°Š½Š¶Š°Š½ - avatar
+ 2
Thanks for clearing it up!
6th Mar 2019, 6:12 PM
Luis Febro šŸ‡§šŸ‡·
Luis Febro šŸ‡§šŸ‡· - avatar