Why is boolean value of 0 false? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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?

5th Jan 2017, 3:53 PM
dorianhoplite
10 Answers
+ 9
@cheese Aren't all numbers except 0 true?
5th Jan 2017, 3:56 PM
Valen.H. ~
Valen.H. ~ - avatar
+ 5
People don't you see it's already answered? Stop posting the same answers again and again... ~_~
6th Jan 2017, 7:13 PM
Valen.H. ~
Valen.H. ~ - avatar
+ 4
^_^ sorry @cheeze ……
5th Jan 2017, 3:58 PM
Valen.H. ~
Valen.H. ~ - avatar
+ 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)
6th Jan 2017, 7:08 PM
Kirk Schafer
Kirk Schafer - avatar
+ 2
0 is false, 1 is true, it is how it is.
5th Jan 2017, 3:54 PM
David Sebastian Keshvi Illiakis
David Sebastian Keshvi Illiakis - avatar
+ 2
Mathematically, 0 is considered as null null in JS is false then 0 is false
5th Jan 2017, 4:12 PM
The Hardworker
The Hardworker - avatar
+ 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.
5th Jan 2017, 4:17 PM
Louis Milotte
Louis Milotte - avatar
+ 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)
5th Jan 2017, 9:33 PM
dorianhoplite
+ 1
@ValentinHacker, it's cheeze with a 'z' xd. Wow, that's news to me, I never know 2 is true...
5th Jan 2017, 3:57 PM
David Sebastian Keshvi Illiakis
David Sebastian Keshvi Illiakis - avatar
+ 1
Lol it's no biggie. Even -2 is true lmao.
5th Jan 2017, 3:58 PM
David Sebastian Keshvi Illiakis
David Sebastian Keshvi Illiakis - avatar