Javascript String Compare == sometimes fails

后端 未结 9 2043
你的背包
你的背包 2020-12-05 17:25

How could the following code sometimes evaluate to false?

(transport.responseText == \'1\' || 
 transport.responseText == \'CARD_VALID\')

M

9条回答
  •  一生所求
    2020-12-05 18:04

    I would advice you to use normalization preferably "NFKC" or "NFKD" as these seem to normalize non-breaking space into regular space.

    So you can write your code as :-

    string1.normalize("NFKC") === string2.normalize("NFKC")
    

提交回复
热议问题