Seemingly identical strings fail comparison

前端 未结 4 580
星月不相逢
星月不相逢 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:35

    BTW. try this code in JS (copy-paste) :)

    console.log("A" == "А");
    

    prints "false" :)

    Comparing strings means comparing character codes. In some fonts, different character codes have the same "picture", like "l" and "I" (first is L, second is i). In my example above, first A is cyrillic, second is latin.

提交回复
热议问题