Short version of the question
true == 'true' //evaluates to false
Why?
Full version
OK, I know that using ==
instead of ===
is a bad practice, but this question was in the FrontendLeague quiz today and I was very surprised with the answer.
My logic was quite straightforward (all the following statements evaluate to true
):
Boolean("true") === true
String(true) === 'true'
'true' ? true : false === true
Nevertheless:
'true' == true // false
true == 'true' // also false
As it was stated by Kyle Simpsons in this great video, most of wtfjs'es aren't actually so wtf and are fully alright according to js specs.
So, could you please explain why 'true' == true
is false?
Thanks!
P.S.
I'm sorry if this question was already asked, but it's pretty hard to find smth by keywords javascript
and true
(wtfjs
gives nothing).
Best regards, Alexander
UPD
Sorry for duplicate, the complete answer can be found here, as mentioned in the comments by Joachim Rohde.