Booleans 15 Flashcards

1
Q

What are the 3 ways to convert an arbitrary value into a boolean?

A

Boolean(x) (recommended of the 3)
x ? true : false (conditional operator)
!!x (logical not operator)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are truthy and falsy values?

A

values that are true/false when coerced into booleans

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are the two logical binary operators?

What is special about them?

A

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 ? : )

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Why is || logical or legacy compared to ?? nullish operator?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly