Ecma262: `2 == true` is false but I think it should be true.

Created on 24 Jun 2020  Â·  5Comments  Â·  Source: tc39/ecma262

2 == true is false and 2 == false is false. ToBoolean(2) is true, I expect 2 == true equal to true.

I think using ToBoolean(number) rather than ToNumber(boolean) in 8, 9 statement in Abstract Equality Comparison makes more sense. What is the point here? I don't get it.

question

All 5 comments

Hmm. Whatever the reason makes it false, it's not possible to change it. It will destroy the web.

Number(true) is 1 though, and Number(false) is 0, so you have a coercion
issue you can very easily solve via if (!!2) ... which is false only with
0 (and -0).

On Wed, Jun 24, 2020 at 5:48 PM Talha Baris notifications@github.com
wrote:

2 == true is false and 2 == false is false. ToBoolean(2) is true, I
expect '2 == true' equal to true.

I think using ToBoolean(number) rather than ToNumber(boolean) in 8, 9
statement in Abstract Equality Comparison
https://tc39.es/ecma262/#sec-abstract-equality-comparison makes more
sense. What is the point here? I don't get it.

—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/tc39/ecma262/issues/2064, or unsubscribe
https://github.com/notifications/unsubscribe-auth/AAAU55K5T47FUGC7GL36AELRYIN6HANCNFSM4OGZL2JQ
.

What is the point here? I don't get it.

Abstract equality, as evidenced by the name, is not based on any concrete rules of how values fit together. It's just a sort of conglomeration of behaviours that the creators of JS felt were "useful" when building it. Aside from being web incompatible to change its behaviour, we have === in the language which you should probably just use instead.

Regardless of the merit of this proposal, the ecma262 issue tracker is not the appropriate place for this discussion. See CONTRIBUTING.md for the best ways to contribute. This particular topic seems to belong on the TC39 Discourse.

Was this page helpful?
0 / 5 - 0 ratings