What two values can a JavaScript Boolean have?
A Boolean has exactly two values: `true` and `false`.
Study 3 Conditionals and Boolean Logic with 12 free online flashcards. Review key terms, definitions, and concepts with this interactive flashcard deck.
What two values can a JavaScript Boolean have?
A Boolean has exactly two values: `true` and `false`.
Which JavaScript values are commonly falsy?
Common falsy values include `false`, `0`, `""`, `null`, `undefined`, and `NaN`. Empty arrays and objects are truthy.
Why prefer `===` and `!==` in JavaScript?
Use `===` for strict equality and `!==` for strict inequality. They do not automatically convert one type into another.
What ordering does JavaScript use when comparing strings?
JavaScript compares strings according to Unicode ordering, which may not match dictionary order in every language.
When is `&&` true?
The `&&` operator is true only when both conditions are true. Use it when all requirements must be satisfied.
When is `||` true?
The `||` operator is true when at least one condition is true. Use it when any acceptable alternative is sufficient.
What does the `!` operator do?
The `!` operator reverses a Boolean value: `!true` is `false`, and `!false` is `true`.
How does JavaScript short-circuit logical expressions?
With `&&`, a falsy left operand skips the right side; with `||`, a truthy left operand skips the right side.
How does `??` differ from `||` for default values?
`??` uses the fallback only for `null` or `undefined`, whereas `||` uses it for every falsy value, including `0` and `""`.
What does an `if...else` statement choose?
An `if...else` statement runs the `if` block when its condition is truthy; otherwise, it runs the `else` block.
How are `else if` branches evaluated?
JavaScript tests an `else if` chain from top to bottom and runs only the first truthy branch. Put more specific or higher-priority tests first.
When is the ternary operator appropriate?
The ternary form is `condition ? valueIfTrue : valueIfFalse`. Use it for a short two-way value choice; use `if...else` for multiple actions.