+ 1

What do we use booleans in?

I just learned about them and i dont see the purpose in using them? can you explain?

18th Sep 2019, 12:57 AM
Paul Perez
Paul Perez - avatar
3 Respostas
+ 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.
18th Sep 2019, 1:22 AM
Rora
0
Thanks
18th Sep 2019, 1:26 AM
Paul Perez
Paul Perez - avatar
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.
20th Sep 2019, 4:52 AM
Ishan Shah
Ishan Shah - avatar