JS Comparison of strings - less than and greater than | Sololearn: Learn to code for FREE!

+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?

3/6/2019 5:51:52 PM

Luis Febro πŸ‡§πŸ‡·

2 Answers

New Answer

+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!