I'm trying to understand the following case:
> "1" === 1
false
> "1" == 1
true
> true === 1
false
> true == 1
true
> "true" === true
false
> "true" == true
false
Why javascript comparison ("true" == true) is false?
Also, what is the proper way to compare this one?
Question has been asked before here.
In essence, "true"
is converted to NaN, while true
is converted to 1 (which is a boolean. Hence, they differ.