Boolean
Anonymous contributor
Published Mar 11, 2022Updated Feb 26, 2023
Contribute to Docs
A boolean holds a true or false value and are mostly used in conditional statements to control a program’s flow of execution. This data type is named after George Boole, a 19th century English logician.
Some languages use comparison operators such as:
>=and<=, for “greater than” and “less than”, respectively.==andisor!=andnotto test for equality and inequality, respectively.
Other languages may use a combination of “falsy” values (e.g. "", null, or 0) and “truthy” values such as 1.
JavaScript Example
The following example uses a comparison operator to return true or false based on the evaluation of the given statement. Then, a JavaScript conditional is used to determines whether the if or else code block will run:
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
Learn General on Codecademy
- Start your programming journey with an introduction to the world of code and basic concepts.
- Includes 5 Courses
- With Certificate
- Beginner Friendly.4 hours
- Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
- Includes 6 Courses
- With Professional Certification
- Beginner Friendly.75 hours