+ 1

What is the deffrence between true and false in constants

4th Jan 2018, 6:34 PM
Raghupatruni Venkatamanas
4 Answers
+ 1
Miroslav, it does make sense when you need to switch between a value and another. You can do this with boolean type values only. var somevar = true; somevar = !somevar; You can do this only with booleans. If you had somevar = 1, the program would have returned an error.
19th Jan 2018, 5:50 PM
Luca Marseglia
Luca Marseglia - avatar
+ 1
You are right Luca. This wasn't my point though. Question is about boolean as a constant, so defining a boolean constant is in my opinion little used. Putting false or true on the code is much easier. Only situation I can think of is when you want to initialize large amount of boolean and still want be able to change it during coding.
19th Jan 2018, 5:57 PM
Miroslav M
Miroslav M - avatar
0
They are variables of the boolean type. Imagine a button that lights up a room. When it's set on true, the room is lit up, false, the room is dark. Their function is just like that, to switch between activating or deactivating something you decide.
4th Jan 2018, 7:22 PM
Luca Marseglia
Luca Marseglia - avatar
0
In programing it does not make much sense to create constants of boolean type. It is just more widely used in other data types (integers, floats,.. and especially strings). That fact is that even phrases "true" and "false" are just representations of 1 and 0. Constants.
19th Jan 2018, 5:37 PM
Miroslav M
Miroslav M - avatar