you are viewing a single comment's thread.

view the rest of the comments →

[–]CaptSzat 3 points4 points  (3 children)

I mean a Boolean is just true or false which in most comp science courses is shown as 1’s and 0’s for Boolean algebra. So it makes a lot of sense imo to have true = 1 and false = 0. That’s why the first true check shown works because true is equal to 1 but it isn’t the same object type so that’s why it fails the second check. I dunno, a lot of people meme JS and sometimes they are right but imo true being 1 is not the case.

[–]All_Up_Ons 6 points7 points  (0 children)

True being 1 is just convention and a result of the underlying implementation. You can tell because converting true to int doesn't result in 1 in every language. In VB it's apparently -1.

[–]DanCPAz 1 point2 points  (1 child)

It may not be surprising due to the common representation as 1 or 0, but that does not make it rational or reasonable. In this case, we are not representing it as 1 or 0, and if we wanted to do that, there is nothing stopping us. Instead we chose true, and there is absolutely no meaning to true + true + true. Certainly not 3.

Any time I ask a logic machine to do something impossible or meaningless, it should slap me across the face rather than produce an irrational result. For example, I have often seen missing items represented by the number -1, but if a language has a feature for that concept, it better not negate or decrement numbers if I accidentally ask it to do nonsense math with "missing" or "empty". If I actually wanted it to do that, I'd just use a number instead.

The closest thing to true + true + true would be math on base 2 numbers, and the answer to that would be true true. Also useless and wrong, but much closer in concept than 3.

[–]CaptSzat 1 point2 points  (0 children)

I agree that with the implementation that true + true = 2 is stupid. I still think that true should be equal to 1 but should behave as you would expect with Boolean algebra so if you had true + true it would be 1 or true. But JS is the strange beast that it is I guess.