Boolean
Part of the Fundamentals section of Coddy's JavaScript journey — lesson 7 of 77.
A Boolean (or bool) is a data type that has only two possible values:
truefalse
You can store a Boolean value in a variable like this:
let isRaining = true;
let hasAccess = false;In this example, isRaining is set to true, and hasAccess is set to false.
Booleans are the building blocks for creating logic in the programs we write. We have a whole chapter about logic and conditions.
Challenge
BeginnerDeclare a variable named boolean and assign it the value true.
Cheat sheet
A bool (Boolean) type has only 2 possible values: true or false.
You can store a Boolean value in a variable like this:
let isRaining = true;
let hasAccess = false;Try it yourself
// Type your code below
let boolean = ?
// Don't change the line below
console.log(`boolean = ${boolean}`)This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Fundamentals
4Operators Part 2
Logical Operators Part 1Logical Operators Part 2Recap - Simple LogicLogical Operators Part 3Type Coercion7Bill Split Calculator
Welcome MessageCalculating The Tip And Total2Variables
NumbersStringBooleanNaming ConventionsEmpty VariablesRecap - Initialize VariablesConstants3Operators Part 1
Arithmetic OperatorsModulo OperatorArithmetic ShortcutsComparison OperatorsStrict vs Loose EqualityRecap - Simple Math6Basic IO
OutputOutput with VariablesType Conversion - Part 1Type Conversion - Part 2Recap - Till 120Recap - True or False