JavaScript For Kids For Dummies
Book image
Explore Book Buy On Amazon

The Boolean data type in JavaScript can store one of two possible values: true or false. Boolean values are the result when you do comparisons in JavaScript. If you ask JavaScript something like: "Is 3 equal to 30?," it will respond with a Boolean value of false.

The Boolean data type is named after the mathematician George Boole, so it's always capitalized.

Do a few experiments with Booleans. Open the JavaScript Console and try typing each of the following statements, pressing Return or Enter after each one to see the result. Note that a single‐line comment is used after each statement to explain what it means. You don't need to type these comments into the console, but you can if you want.

1 < 10 // Is 1 less than 10?
100 > 2000 // Is 100 greater than 2000?
2 === 2 // Is 2 exactly equal to 2?
false === false // Is false exactly equal to false?
40 >= 40 // Is 40 greater than or equal to 40?
Boolean (0) // What is the Boolean value of 0?
Boolean (false) // What is the Boolean value of false?
"apples" === "oranges" // Is "apples" exactly equal to "oranges"?
"apples" === "apples" // Is "apples" exactly equal to "apples"?

In addition to the statements you would expect to be false, JavaScript also considers the following values to be false:

0 null undefined
" (an empty string) false

About This Article

This article is from the book:

About the book authors:

Chris Minnick and Eva Holland are experienced web developers, tech trainers, and coauthors of Coding with JavaScript For Dummies. Together they founded WatzThis?, a company focused on training and course development.

This article can be found in the category: