0

In JS I have two variables:

let str1 = '\u04101';
let str2 = 'A1';

If I use console.log for each of them then 'A1' will appear in console for both.

So console.log(str1); // returns A1

If I compare them in a IF statement it returns FALSE.

console.log(str1 == str2) // returns FALSE

How to return TRUE in compare case?

I tried using normalize method of String but without any success.

Iulian Boiculese
  • 393
  • 1
  • 6
  • 16
  • 1
    "If I use console.log for each of them then 'A1' will appear in console for both." — No, it won't. `U+0410 : CYRILLIC CAPITAL LETTER A` and `U+0041 : LATIN CAPITAL LETTER A` might be indistinguishable to your eyes, but they are not the same character. – Quentin Dec 17 '21 at 14:11
  • 1
    See codepoints for each in your console: `['\u04101', 'A1'].map(str => [str, [...str].map(s => [...new Array(s.length).keys()].map(i => s.codePointAt(i)))])` – jsejcksn Dec 17 '21 at 14:24
  • @jsejcksn, indeed, they are different. I used str1 = str1.replace(/\u0410/g, 'A') in order to get the compare correctly – Iulian Boiculese Dec 17 '21 at 14:38

0 Answers0