Lesson 22 of 48
46%
JavaScript Booleans
A boolean is a tiny answer: true or false.
Programs use booleans to make choices.
Think of a light switch. On or off. No maybe.
1
true and false
2
Comparisons make booleans
3
Truthy and falsy
4
Boolean()
Writing booleans
Write true and false with no quotes.
They are keywords, not text.
javascript
Comparisons create booleans
Ask a question with operators. Get true or false back.
javascript
Use them in if
Booleans steer the path your code takes.
javascript
Truthy and falsy
In choices, some values act like false.
Those are called falsy.
1
falsy: false, 0, "", null, undefined, NaN
2
most other values act like true
javascript
Boolean converter
Boolean(value) shows the truthy or falsy result.
javascript
Tip: Keep real booleans for yes or no flags. It makes if statements easier to read.
Test yourself
Three quick questions made just for this lesson. Earn 10 XP per correct answer.