Booleans — primitive type

George Boole developed the true/false system logic in the 19th century. Consequently, the word Boolean is derived from his name.

In JavaScript, Boolean logic allows your program to make decisions. A Boolean logic statement consists of a condition that evaluates to either true or false. You can think of the condition as a question that has one of two possible answers:

  1. yes or no,
  2. ON or OFF, or
  3. positive or negative
  4. true or false

When working with Boolean logic, keep in mind there is no "maybe" or third possibility. Thus a Boolean type a can be used anytime there is only one possible outcome out of two possible outcomes.

A Boolean type is useful in situations where you want the program to act according to the value it represents. For instance, let's say our program has to determine whether a person is at least 18 years of age to apply for a driving license. In the program, we would ask the applicant's date of birth and then we would calculate applicant's age. Then we would ask the following questions programmatically: is this applicant's age at least 18 years of age. The answer to this question would be either yes or no. In this case, we could use a Boolean type to store our response. If our response is yes to our question, then, the applicant does meet the minimum age requirement for the license. If, however, our response if no, then the applicant does not meet the minimum age requirement. The following summarizes our Boolean logic example:

Boolean logic example