For web developers, Boolean variables have only two possible values: true or false. Computers need a way to determine whether something is true or false in order to make decisions. The decision-making process makes it possible for a computer to perform a task, to choose between two tasks, or to stop performing a task.
Boolean variables are traditionally used to make a decision or to tell the user the truth value of the Boolean variable (possibly as the result of performing a calculation or checking the status of data).
In most cases, you create a Boolean variable by assigning the variable a value of true or false like this: var MyBoolean = true. You can also assign a variable a Boolean value by using an expression that equates to true or false, such as var MyBoolean = 3 < 4. In this case, 3 is less than 4, so MyBoolean is true. The < symbol is an operator.
You can create Boolean values by using the new operator. The statement MyBoolean = new Boolean(); creates a new Boolean variable that’s initialized to false. You can also add a value or an expression between the parentheses. Some odd things happen in this situation.
The Boolean new operator accepts all sorts of inputs. The following list of inputs creates variables that contain a value of false: