if ('11' < '3') alert('true');
It’s obvious that it’s not comparing them by length but by encoding instead. However, I don’t understand how it works. I need some explanation 🙂
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Strings are compared lexicographicaly. i.e. character by character until they are not equal or there aren’t any characters left to compare. The first character of ’11’ is less than the first character of ‘3’.
If we use letters then, since
bis not less thana,abcis not less thanaaa, but sincecis less thand,abcis less thanabd.You can explicitly convert strings to numbers: