Booleans: True or False

Grade 2, page 7 of 13. A one-minute read.

A boolean is the simplest type of all. It has only two possible values: true and false. That's it. Yes or no. On or off. Light switch up or light switch down.

JavaScript
const isRaining = true;
const hasHomework = false;

console.log(isRaining);
console.log(hasHomework);

It prints

true
false

Notice there are no quotes. true is a boolean. "true" is a string containing four letters. Very different things!

Booleans are named after George Boole, a 19th-century mathematician who worked out the math of true-and-false logic long before computers existed.

You'll usually get booleans as the answer to a question, like "is 10 bigger than 5?":

JavaScript
console.log(10 > 5);
console.log(10 < 5);
console.log("hello".includes("ell"));

It prints

true
false
true

Booleans might seem boring now, but they're the secret ingredient that lets programs make decisions. In Grade 4, you'll use them to write code like "if the password is correct, let them in; otherwise, show an error." They're kind of a big deal.

Reading is step one

CurlyScript turns these notes into a game: short questions, an explanation after every answer, and a test at the end of each grade. Free, with nothing to sign up for.

Start learning