+ 1

It's too hard to uderstand boolean values. can you help me pls?

11th May 2016, 4:45 PM
Augustin J
Augustin J - avatar
5 Respuestas
+ 11
Numbers are simple, right? You can compare them, you can add them together, etc. Maybe you have some code which tells you how often it has rained this month and it spits out 5. Maybe you have some code which checks how much money is on your bank account and it spits out -300. A lot of times however, a number is just too much, as the thing you are trying to do has only two possible outcomes: true or false. Is your front door open? Either it is (true), or it isn't (false). You could have code that spits out 1 if your door is open and 0 if it is closed, and in fact some other programming langages have no booleans and do exactly that, but for cases like this, us Javascripters just use the labels true and false instead. Besides this, booleans handle just like numbers. You can put them in variables and carry them around, like var x = true; and in fact Javascript will give you booleans as a result to a lot of things. Check this: var x = 5 > 4; x will now contain true, since 5 is in fact bigger than 4. Or this: var x = 3 == 2; x will now contain false, since 3 does not equal 2. You can even compare booleans: var x = true == false; x will now contain false since true does not equal false. I hope this helps! :)
11th May 2016, 9:00 PM
Schindlabua
Schindlabua - avatar
+ 3
a boolean is either true or false 3+3=5 which is false so the correct boolean would be "False"
10th Jun 2016, 7:41 PM
Austin Taylor
Austin Taylor - avatar
0
it's simple compare the values(condition) than if values equal true otherwise false
13th Jun 2016, 5:50 AM
M Waqar Tufail
M Waqar Tufail - avatar
0
bools are like 1 0 in electronics. to operate with its values you must use boolean math rules like OR AND NOT and combine it with condition statements like IF WHILE etc.
2nd Jul 2016, 11:32 AM
Elad Kipiani
Elad Kipiani - avatar
0
feels more logic when you write your code in a simple understandable way. that's why good coders don't use pathetic x and y variable names. instead, they use variable names like this: var myApples = 10; var familyMembers = 5, var applesPerPerson; var isOutofApples; if (applesPerPerson == 2) { isOutofApples = true; } else if (applesPerPerson == 1) { isOutofApples = false; } that's why we always like to name our booleans with the prefix "is"... so that it looks like a yes/no question
22nd Jul 2016, 2:42 PM
Dr.Na'el Hariri
Dr.Na'el Hariri - avatar