Selection

Objectives

  • Use if/else selection statements in JavaScript
  • Use switch selection statements in JavaScript
  • Use the conditional operator

Selection: if/else

Examples:

Selection: switch

Mozilla article on switch statements

Example:

Selection: conditional operator, || operator

  • The conditional operator "?:" takes three operands. If the first operand evaluates to true, the entire expression assumes the value of the second operand. If the first operand evaluates to false, the entire expression assumes the value of the third operand.
  • The || (OR) operator can be used to choose an alternative value for an expression if a primary value evaluates to false.

Example:

Examples