What do we use booleans in? | SoloLearn: Learn to code for FREE!

+1

What do we use booleans in?

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

9/18/2019 12:57:40 AM

Paul Perez

3 Answers

New Answer

+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.