Truthy and Falsy Values
Know which values evaluate as true or false.
Truthy and Falsy
In a boolean context such as an if statement, every JavaScript value is treated as either truthy or falsy. Falsy values behave like false; everything else is truthy.
if ("hello") {
console.log("strings are truthy")
}The Falsy List
There are exactly eight falsy values. Memorize them, because everything not on the list is truthy.
- false
- 0 and negative zero
- empty string
- null
- undefined
- NaN
- BigInt zero
console.log(Boolean(0))
console.log(Boolean(""))
console.log(Boolean(null))All lessons in this course
- Truthy and Falsy Values
- Loose vs Strict Equality
- Implicit Coercion in Operations
- Explicit Conversion Techniques