I was wondering why the output of the following is all false.
12 > "goodbye"
12 < "goodbye"
10 > "2 beers"
I've looked all over the web and I haven't found anything that explains how to handle strings in comparison to numbers in javascript.
I was wondering why the output of the following is all false.
12 > "goodbye"
12 < "goodbye"
10 > "2 beers"
I've looked all over the web and I haven't found anything that explains how to handle strings in comparison to numbers in javascript.
When you try to compare strings to ints using equality operators, javascript will try to use the charCodes of the string's characters to compare to the number, which will naturally give some funky answers. You really shouldn't need to do comparisons with alphanumeric strings anyway, if you need to compare an int to a numeric string ("10" > 2) you can just use the parseInt() function: http://www.w3schools.com/jsref/jsref_parseint.asp