Js Fundamentals - Conditional if Flashcards
1
Q
Boolean Conversions
A
Boolean conversion The if (…) statement evaluates the expression in its parentheses and converts the result to a boolean.
Let’s recall the conversion rules from the chapter Type Conversions:
A number 0, an empty string “”, null, undefined, and NaN all become false. Because of that they are called “falsy” values.
Other values become true, so they are called “truthy”.
2
Q
The if statement may contain an optional “else” block. It executes when the condition is falsy.
A
Sometimes, we’d like to test several variants of a condition. The else if clause lets us do that.
3
Q
A complex ternary operator expression
A
if (age < 3) { message = 'Hi, baby!'; } else if (age < 18) { message = 'Hello!'; } else if (age < 100) { message = 'Greetings!'; } else { message = 'What an unusual age!'; }