+ 1
What do we use booleans in?
I just learned about them and i dont see the purpose in using them? can you explain?
3 odpowiedzi
+ 2
Whenever you need something to be either true or false, and nothing else. Say you want some code to run only if a different piece of code ran. Since ran/not ran is a binary choice, boolean datatype would make sense here. Python example:
x = 2
ran =False
if x == 3:
x += 1
ran = True
if ran:
x += 2
Now, this is toy example, but Booleans can be very useful.
0
Thanks
0
Hi Paul Perez,
Generally boolean variables are used to check the conditions. If you want to manipulate DOM on the basis of condition then you required boolean variables for manipulation.
Example, I am working in angular so I use boolean variable to hide or display some input fields of the form.