Array
University of Oregon

Logic Operators && Truthiness

Logical operators are typically used with Boolean (logical) values. When they are, they return a Boolean value. However, the && and || operators actually return the value of one of the specified operands, so if these operators are used with non-Boolean values, they may return a non-Boolean value.

|| returns the first truthy value, and if none are truthy, it returns the last value (which is a falsy value).

&& returns the first falsy value, and if none are falsy, it return the last value (which is a truthy value).

! always returns a Boolean value

Experiment in your console to see for yourself.

Skip to toolbar