Strange comparison in a third-party javascript library

While I was correcting some js syntax to avoid minimization problems, I noticed this block in a third-party js library:

if ('\u0041' == 'A') { var u = n.userAgent; if (u.indexOf('Safari') == -1) { [...] } } 

There is no other condition in the block and basically checks the type and version of the browser ... in any case, I don’t understand why it should compare the unicode code for the character β€œA” and, well, β€œA”, the character!: /

Has anyone encountered this condition before? Am I missing something or is it useless?

+4
source share
2 answers

It should be a pretty old library that is testing javaScript support for Unicode .

For an old browser, such as Netscape Navigator 4, it only supports Latin-1 encoding '\xXX' , different from full Unicode support '\uXXXX'

+3
source

I think he used to determine if the browser is safari 2.0.4, because it has problems understanding regular expressions: https://discussions.apple.com/thread/689517?start=0&tstart=0

+1
source

Source: https://habr.com/ru/post/1381851/


All Articles