Why is one line bigger than the other when comparing strings in JavaScript?
I see this code from the book:
var a = "one"; var b = "four"; a>b; // will return true but it does not mention why "one" is greater than "four." I tried c = "a" and it is smaller than a and b. I want to know how JavaScript compares these strings.
Because, as in many programming languages, strings are compared lexicographically .
You can think of it as a more convenient version in alphabetical order , the difference being that letter ordering covers only 26 characters a through z .
This answer is in response to java , but the logic is exactly the same. Another good one: String Compare "Logic" .
βoneβ begins with βoβ, βfourβ begins with βfβ, βoβ later in the alphabet than βfβ, so βoneβ is greater than βfourβ. See this page for some good examples of JavaScript string comparisons (with explanations!).
Javascript uses lexicographic order for the operator . 'f' continues to 'o', so comparing "one"> "four" returns true
Comparison operators are used in logical operators to determine the equality or difference between variables or values.
You can see that each statement:
http://www.w3schools.com/js/js_comparisons.asp
When a string (Text) you should use ==, === or! = When comparing numbers, you can use> =, <=, etc.
you need to send them an integer
Here is an example
if (parseInt($('#myRangeMin').val()) >= parseInt($('#myRangeMax').val()))