You've probably heard that computers think in ones and zeroes. This is true.
In the black-and-white world of computers, we have a type of data that can be only one of two values: true
or false
. These are called Boolean values.
Try running this code in the editor:
true
Notice how it doesn't throw an error, but returns true
as the result? Both true
and false
are JavaScript keywords.
Remember that JavaScript only recognizes certain keywords as valid code. Any of these words would throw an error:
test
correct
wrong
Many aspects of programming are built on Boolean values. We can make something happen only if a condition is true
or false
. We can use these values to represent on/off switches in user settings or app configuration.
Now that you know what a Boolean value is, we can start working with them.