The same applies to '1\t'(and possibly others).
'1\t'
if (1 == '1\n') { console.log('Equal'); } else { console.log('Not Equal'); }
As already mentioned, if you compare number == string, it will automatically try to convert the string to a number. \nand \tare just whitespace characters and therefore are ignored.
number == string
\n
\t
This and similar behavior can be quite confusing, leading to the following situations:
(Image taken from: https://www.reddit.com/r/ProgrammerHumor/comments/3imr8q/javascript/ )
(==) , , . , JavaScript , , .
==
1 Number, '1\n' Number, comparison!
1
Number
'1\n'
comparison
Number() ('1\n') 1: -
Number()
('1\n')
Number('1\n') === 1
Strict equality using ===, - . , .
Strict equality using ===
, 1 === '1\n' false
1 === '1\n'
false
Source: https://habr.com/ru/post/1690866/More articles:Automapper does not correctly display a null List element when a condition is specified! = Null - c #C ++ beginner: Why doesn't the compiler find my functions in the header? - c ++SonarQube process terminated with exit value [es]: 137 - debianWhat does "S" mean in hexadecimal number? - vb.netTwo different results for "1" + "1" and "1" - - "1" in javascript - javascriptHow to use PresentationCore in WebAPI hosted on Azure? - wpfHow to find input string with mixed types - pythonCoordinator mark is dead - apache-kafkaWhy can't I return the ByteString from the handler to Yesod? - haskellConvert img - white dots appear on chronium - javascriptAll Articles