JS Built-ins
Operatorsbeginner

Operators β€” logical &&, ||, ! and short-circuit

Logical operators return values, not just booleans

&& returns the first falsy value or the last value. || returns the first truthy value or the last value. This enables short-circuit evaluation.

Challenge: Write shortCircuit() returning:

  • and: result of null && 'never'
  • or: result of null || 'fallback'
  • notEmpty: result of !''
πŸ’‘ Hints (2)
  • β€’ && stops and returns the first falsy value
  • β€’ || stops and returns the first truthy value