With the Boolean data type, there are only two values:
false to represent those values. You will use the Boolean data type when you need the answer to a yes or no (true and false respectively) question. That most often occurs in conditional statements (if/else statements), loops (for loops and while loops), and in flags to test whether something is true of false.
When initializing a variable with a Boolean value, you must leave the quotes off. If you were to use quotes, you would be setting your variable to a string value. For example:
var boolean_variable = true; var string_variable = "true"; document.write(boolean_variable); document.write(string_variable); alert("boolean_variable has a data type of " + typeof (boolean_variable)); alert("string_variable has a data type of " + typeof (string_variable));This example prints
truetrueto the screen and then an alert box with the text
boolean_variable has a data type of booleanpops up, followed by another alert box that has the text
string_variable has a data type of string.