0
Why "2" > "12" greater ?
Anyone know why
4 Respuestas
+ 8
Because "2" and "12" are both strings. In strings, the comparison is done character by character. The nth letter of the first string is compared with the nth letter of the second one. As soon as a character is found in the first string which is greater (for '>' operator) than the one in second string, true is returned.
In the case of "2" and "12", first '2' and '1' will be compared. As the ascii value of '2' > ascii value of '1', true is returned.
+ 2
Por lo que veo estas evaluando cadenas de texto, que es muy diferente a evaluar valores bien numéricos
+ 1
mention any one language in the tags.
0
I understand but "5">"4" in case this statement "12"<"2" , "2" is greater because compiler check 1st digit compare.