+ 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 Réponses
+ 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