The number and string data types have an infinite number of possible values. The Boolean data type, on the other hand, has only two. As we saw in Chapter 2, Lexical Structure, the two legal Boolean values are the keywords true and false. A Boolean value represents a "truth value"--it says whether something is true or not.
Boolean values are generally the result of comparisons we make in our JavaScript programs. For example, when we write:
a == 4
if (a == 4) b = b + 1; else a = a + 1;
Instead of thinking of the two possible Boolean values as true and false, it is sometimes convenient to think of them as "on" (true) and "off" (false) or "yes" (true) and "no" (false). Sometimes it is even useful to consider them equivalent to 1 (true) and 0 (false). (In fact, JavaScript does just this and converts true and false to 1 and 0 when necessary.)
C and C++ programmers should note that JavaScript has a distinct Boolean data type, unlike C and C++ which simply use integer values to simulate Boolean values. Java programmers should note that although JavaScript has a Boolean type, it is not nearly as "pure" as the Java Boolean data type--JavaScript Boolean values are easily converted to and from other data types, and so in practice, the use of Boolean values is much more like their use in C and C++ than in Java.