DEV Community

front_end_shifu_2022
front_end_shifu_2022

Posted on

Falsy values

what are truthy and falsy values?
truthy values:
these values are actually not a boolean values but they act like True .

falsy values:
These values are actually not false(boolean) but they act as a false. it includes 0,null,"",undefined,false,NAN.

// if the first operand is truthy,
// AND returns the second operand:
alert( 1 && 0 ); // 0
alert( 1 && 5 ); // 5

// if the first operand is falsy,
// AND returns it. The second operand is ignored
alert( null && 5 ); // null
alert( 0 && "no matter what" ); // 0

Note: All values are truthy unless they are defined as falsy.

Top comments (0)