Beyond numbers and text, programs often need to represent simple "yes" or "no" states, like whether a light switch is on or off.
JavaScript has a specific data type for this kind of information.
Engagement Message
Can you think of a situation where you only need a true/false answer?
This data type is called a Boolean, named after George Boole. In JavaScript, the type is called boolean
.
A boolean variable can only hold one of two possible values: true
or false
.
Engagement Message
Why do you think these specific words are used?
It's crucial to remember that true
and false
must be lowercase in JavaScript. True
or False
(capitalized) will cause an error.
Engagement Message
How is true
different from the string "true"
?
Booleans are fundamental for making decisions in code. We often get boolean values by comparing other values.
