Read the manual about the lines: Character-by-character comparison
But I did not fully understand the essence of the comparison:
"2" > "15"// Выдает true Why is it true?
If you compare the characters,
"2" > "1"// true Why is that?
Read the manual about the lines: Character-by-character comparison
But I did not fully understand the essence of the comparison:
"2" > "15"// Выдает true Why is it true?
If you compare the characters,
"2" > "1"// true Why is that?
The term is directly compared character by character - the first with the first, the second with the second:
If the first letter of the first line is greater, then the first line is greater, regardless of the other characters:
The non-strict equality operator == compares by type of variables. The strict equality operator === compares the numeric character code. Because 2 comes after 1 (has a larger code for Unicode), then a two more.
More information on the link: String Comparison
A bit of specification , excerpt algorithm compared lines:
for the case x<y
If both operands are strings, then:
If y is the prefix x , return false . (The string p is the prefix of the string q , if q can be obtained by appending another string r to the string p . Note that any string is a prefix for itself, since r can be an empty string.)
If x is the prefix y , return true .
Let k be the smallest non-negative index for which the character code from string x is different from the character code from string y (such k exists if none of the compared strings is a different prefix.)
Let m be the character code x [k]
Let n be the character code of y [k]
If m <n , return true . Otherwise, return false .
Please note: string comparison uses just the lexicographic order of character code sequences. There is no attempt to use the more complex, semantically oriented definitions of the equality of strings or characters and ordering schemes defined in the Unicode specification. Therefore, strings that are canonically equivalent according to the Unicode standard may be unequal. In fact, this algorithm assumes that the rows are already in normalized form. Also note that for strings containing additional characters, the lexicographic ordering of the values of UTF-16 character codes is different from the same for code point values.
In relation to the code in question:
"2"> "15"
Strings are not prefixes of each other.
k == 0,
m = "2" [0] == '2' = 50
n = "15" [0] == '1' = 49
50> 49 -> the result of the comparison is true .
Source: https://ru.stackoverflow.com/questions/529588/
All Articles
2greater than symbol1, therefore("2" > "15") === true. And about the second comparison, you're lying:("2" == "1") === false- Dmitriy Simushevvalueproperty is always a string. - Grundy