+ 2
Why is boolean value of 0 false?
I understand why null, undefined and empty strings are false. But 0 is a value, it's not the same as null, so why is it false then?
10 Respuestas
+ 9
@cheese Aren't all numbers except 0 true?
+ 5
People don't you see it's already answered? Stop posting the same answers again and again... ~_~
+ 4
^_^ sorry @cheeze ……
+ 3
I suppose if you really wanted to get electrical engineering on this...0 indicates the lower of the two voltages representing memory values. There might be other voltage levels in the system, but if you set a memory cell to 0.2V and the 'reference 0' is 0.2V, there is 'no potential difference' (no WORK value) between your voltage and reference ground.
Any other voltage (usually within a certain tolerance, like +-1.0; the same concept used in sigmoid functions in AI) represents a different potential (so has value on its return to reference ground, like +-work)
+ 2
0 is false, 1 is true, it is how it is.
+ 2
Mathematically, 0 is considered as null
null in JS is false
then 0 is false
+ 2
It's leftover from machine code. In binary 1 is on, 0 is off. To machines doing checks on power, 1 returns true 0 returns false.
If you perform checks on all other numbers you will receive a true because the value is set, not necessarily because the value itself is true... unless it is.
However, if you deal with languages that have compilers or use certain error handling methods you will see "1" is an error or false attempt to perform an action.
+ 2
@Louis Milotte
It's not exactly what I asked (probably because my question wasn't specific enough), but your answer gave me the basis I needed for figuring it out by myself. Since for some reason I can't give you an upvote, I am doing it this way. Thanks Louis (and to others who put some effort in answering my question)
+ 1
@ValentinHacker, it's cheeze with a 'z' xd. Wow, that's news to me, I never know 2 is true...
+ 1
Lol it's no biggie. Even -2 is true lmao.