JavaScript mysterious behavior: unequal equal

I really do not know how this is possible, and I could not reproduce the error in a simplified environment, say, JSFiddle. But here is how it looks in my application.

I am trying to convert a value that can be "True", "False" or "something else" string to boolean if it is either True or False. In most cases, it works very well (although they can be a smoother conversion method), as shown in the image below.

enter image description here

however, sometimes it fails, and the value of the clock shows the following:

enter image description here

So, a string variable with the value "True" is not equal to the string literal "True". I'm lost. How is this possible? What am I missing here?

Thanks in advance

+5
source
2

, , . Google Chrome:

> var a = "foo";
> var b = "foo\r";
> a
"foo"
> b
"foo"
> a === b
false

, , .length .charAt(i) "" , , .

+4

, === "True", , . , :)

0

All Articles