truthy and falsy
In JavaScript, values that count as true or false when used in a condition: false, 0, empty string, null, undefined and NaN are falsy, everything else is truthy.
In more detail
clsx relies on this: it keeps class names whose condition is truthy and drops falsy ones, so clsx("btn", isActive && "btn-active") adds the second class only when isActive is true. Empty arrays and objects are truthy, which surprises many newcomers.
Related terms
- clsx — A tiny JavaScript function that builds a class string from strings, objects and conditions, skipping anything falsy.
- Boolean — A value that can only be true or false.
Taught in
- Class Variance Authority: Type-Safe Variant & Prop Orchestration — Design Systems & Component Engineering