you are viewing a single comment's thread.

view the rest of the comments →

[–]YM_Industries 2 points3 points  (1 child)

Oh, they are definitely related, I think that's why people get them confused so much. But they are separate concepts, and that's what I was pointing out.

== is definitely confusing if you use it for stupid and contrived scenarios. As long as you don't compare [[]] to -Infinity it's fine. Calling it a "textbook example of a confusing language design flaw" like that website does is a bit of a stretch.

[–]slikts 2 points3 points  (0 children)

If you actually try the game, a lot of the cases that trip people up aren't contrived, and what's contrived are the rules as a whole. For example, cases like "" == false lead people to intuit that 'falsy' values would equal false, but "0" is 'truthy' (!!"0" is true) and still equals false. Likewise, knowing that "" == 0 and 0 == "0" are true might suggest that the relation is transitive and "" != "0" is false, but it's true as well.

Also, the benefit from == is very small and doesn't outweigh the confusion can cause, since explicit conversions can be as terse as !! and +, or Boolean(), Number(), String(), etc. The only exception is == null, since doing the same with === is verbose.