console.log("20">10); //true
console.log("20a">"10"); //true
console.log("20a">10); //false
I want to know why the last one turns false.
And “20a” transforms to what before comparing.
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.
From the MDN page on comparison operators:
This converts
"20"to a number20and compares it. Since20is greater than10, it is true.This compares the two strings. Since
"20a"is greater (alphabetically) than"10", it is true.This converts
"20a"to a number. The result isNaN(do+"20a"to see this in action).NaNis not greater than any number, so it returns false.