Booleans 15 Flashcards
What are the 3 ways to convert an arbitrary value into a boolean?
Boolean(x) (recommended of the 3)
x ? true : false (conditional operator)
!!x (logical not operator)
What are truthy and falsy values?
values that are true/false when coerced into booleans
What are the two logical binary operators?
What is special about them?
logical or (||)
logical and (&&)
they are value preserving and short-circuiting
value preserving: the operands are evaluated as booleans but returned unchanged
short-circuiting: if the first operand determines the result, the second operand will not be evaluated. (this is also the case with the conditional operator ? : )
Why is || logical or legacy compared to ?? nullish operator?
Because logical or will move on if the first operand is any falsy value, while nullish operator will only move on if it is undefined or null.