Boolean
We have learned and used all but one last primitive variable. Are you ready to see it in action? Booleans are simple! They are really only place-holders that can hold only one of two possible values: true or false (0 or 1, yes or no...)
Boolean values can be used to state whether a statement is right or wrong. It has only two options: true or false. We may also take this as 0 or 1 if we are using some other programming languages like c and c++. A Boolean value is like a switch which has only two options: on or off.
Assigning and working with Boolean Variables
We can assign a Boolean value to a variable using var a:Boolean = true;. This means the variable is declared as a Boolean value and the option true is assigned to it. We can't assign any other value (such as string or number) to this Boolean variable other than true or false (0 or 1.) However, if we want to change the Boolean value from true to false later in the program, we can type a= false. This will turn the Boolean value of the variable a to false. Remember that these Boolean values (true or false) should be written directly without any double or single quotes.
Ready to Level Up Your Skills?
Join thousands of learners on 02GEEK and start your journey to becoming a coding expert today!
Enroll Now for Free!