Maven (famous)@lemmy.zip to Programmer Humor@programming.dev · 1 year agoModern Programminglemmy.zipimagemessage-square76linkfedilinkarrow-up1598arrow-down18
arrow-up1590arrow-down1imageModern Programminglemmy.zipMaven (famous)@lemmy.zip to Programmer Humor@programming.dev · 1 year agomessage-square76linkfedilink
minus-squarekn0wmad1c@programming.devlinkfedilinkEnglisharrow-up2arrow-down2·edit-21 year agonum % 2 isn’t a boolean result in any of these languages, so I feel like it would always output “odd” Edit: 0 is false, everything else is true.
minus-squaremoomoomoo309@programming.devlinkfedilinkEnglisharrow-up8·1 year agoAll of those languages will convert numbers into booleans, 0 is false, all other numbers are true.
minus-squareSatyrSack@lemmy.sdf.orglinkfedilinkarrow-up2arrow-down1·1 year agoIt doesn’t make sense. I understand it, but it doesn’t make sense.
minus-squareLifter@discuss.tchncs.delinkfedilinkarrow-up1·1 year agoI agree. If anything it should check if there is a nuumber and 0 is clearly a number.
minus-squareHammerheart@programming.devlinkfedilinkarrow-up2·1 year agoIt does. Empty collections, 0, None
minus-squareKaboom@reddthat.comlinkfedilinkarrow-up7arrow-down4·1 year ago0 is false in C, Python, and JS. It should work
minus-squareColloidal@programming.devlinkfedilinkarrow-up3arrow-down1·1 year agoThe joys of dynamic typing.
minus-squareMaven (famous)@lemmy.zipOPlinkfedilinkarrow-up3arrow-down1·1 year agoIn JS 0 is the same as False
minus-squareLifter@discuss.tchncs.delinkfedilinkarrow-up1·1 year agoThey are not the same, but 0 can be implicitly converted to false. What do you get if you do: 0 === false
minus-squaremarcos@lemmy.worldlinkfedilinkarrow-up2·1 year agoYou’d be surprised. But seriously, numbers can be used as booleans in an impressive number of languages. Including machine code for almost every machine out there.
num % 2isn’t a boolean result in any of these languages, so I feel like it would always output “odd”Edit: 0 is false, everything else is true.
All of those languages will convert numbers into booleans, 0 is false, all other numbers are true.
Ah that makes sense.
It doesn’t make sense. I understand it, but it doesn’t make sense.
I agree. If anything it should check if there is a nuumber and 0 is clearly a number.
deleted by creator
deleted by creator
deleted by creator
It does. Empty collections, 0, None
0 is false in C, Python, and JS. It should work
The joys of dynamic typing.
In JS 0 is the same as False
They are not the same, but 0 can be implicitly converted to false.
What do you get if you do: 0 === false
Explosion?
You’d be surprised.
But seriously, numbers can be used as booleans in an impressive number of languages. Including machine code for almost every machine out there.