Seemingly identical strings fail comparison

前端 未结 4 579
星月不相逢
星月不相逢 2021-01-18 01:50

I am encountering a strange issue while comparing two strings. Here is my code:

console.log(x == y);
console.log(\"\'\" + x + \"\'==\'\" + y + \"\'\");
conso         


        
4条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-18 02:21

    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.

提交回复
热议问题