Truthy and Falsy
Definition
In JavaScript, every value is either truthy or falsy when evaluated in a boolean context. Falsy values are: `false`, `0`, `''`, `null`, `undefined`, `NaN`, and `0n`. Everything else is truthy, including empty arrays and objects.
Code Example
Javascript
Tip: Modify the code above and click “Run” to see the results
Learn More
Related Terms
Type Coercion
JavaScript's automatic conversion of values from one type to another during operations. Implicit coercion happens with operators like ==, +, and in boolean contexts. Explicit coercion uses functions like Number(), String(), Boolean().
Nullish CoalescingThe ?? operator that returns the right-hand operand when the left-hand operand is null or undefined. Unlike ||, it does not treat 0, '', or false as nullish, making it safer for default values.