I am encountering a strange issue while comparing two strings. Here is my code:
console.log(x == y);
console.log("'" + x + "'=='" + y + "'");
console.log(typeof(x));
console.log(typeof(y));
In the console, I have :
false
'1Ä4±'=='1Ä4±'
string
string
I guess my strings contain strange characters, so how should I compare them?
I read Javascript string comparison fails when comparing unicode characters but in my case, x
and y
come from the same source and have the same encoding.
The Ä
in your strings can be represented either as a single UNICODE character (Latin Capital Letter A With Diaeresis, U+00C4), or as a composite character consisting of Latin Capital Letter A (U+0041) followed by a Combining Diaeresis (U+0308) diacritic.
There also might be any number of Zero-Width Spaces (U+200B), as well as other "invisible" characters in your strings.
Therefore, both strings may render the same, but actually be different.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With