+ 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?
2 Antworten
+ 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.
+ 2
Thanks for clearing it up!