Basics
JS Booleans
JavaScript Boolean Values
JavaScript booleans handle true/false, with truthy/falsy evaluations.
What are Booleans?
In JavaScript, a boolean represents one of two values: true
or false
. Booleans are commonly used in control structures such as if
statements and loops to determine the flow of a program based on conditions.
Boolean Values in JavaScript
The boolean data type has two literal values: true
and false
. These values are case-sensitive and must be written in lowercase.
Truthy and Falsy Values
In JavaScript, a value that is not a boolean can still behave like a boolean in conditional contexts, such as if
statements. These values are classified as either truthy or falsy:
- Truthy values are treated as
true
in logical expressions. - Falsy values are treated as
false
in logical expressions.
JavaScript considers the following values as falsy:
false
0
""
(empty string)null
undefined
NaN
(Not-a-Number)
Everything else is considered truthy.
Boolean Operations
JavaScript provides several operations that work with boolean values, including logical operators such as &&
(AND), ||
(OR), and !
(NOT).
Basics
- Introduction
- Where To
- Output
- Syntax
- Comments
- Variables
- Scope
- Hoisting
- Errors
- Data Types
- Operators
- Ternary Operator
- Short-Circuit Evaluation
- If Else
- Switch
- Loops
- For...Of/For...In
- Functions
- this Keyword
- Objects
- Arrays
- Strings
- Template Literals
- Numbers
- Number Properties
- Dates
- Math
- Booleans
- Type Conversion
- Destructuring
- Spread/Rest
- RegExp
- Strict Mode
- Modules
- Security Basics
- Debugging
- Best Practices
- Mistakes
- Performance
- Reserved Words
- Sets
- Maps
- Bitwise
- Array Const
- Previous
- Math
- Next
- Type Conversion