Conditionals control behavior in JavaScript and determine whether or not pieces of code can run. The most common type of conditional is the if statement, which only runs if the condition enclosed in parentheses () is truthy.

See the Pen thecodelog.com - JS Conditionals 1 by Deano (@deangilewicz) on CodePen.

You can extend an if statement with an else statement, which adds another block to run when the if conditional doesn’t pass.

See the Pen thecodelog.com - JS Conditionals 2 by Deano (@deangilewicz) on CodePen.

You can also extend an if statement with an else if statement, which adds another conditional with its own block.

See the Pen thecodelog.com - JS Conditionals 3 by Deano (@deangilewicz) on CodePen.

A second way to use a conditional statement is with the ternary operator. The conditional (ternary) operator is the only JavaScript operator that takes three operands. This operator is frequently used as a shortcut for the if statement.

See the Pen thecodelog.com - JS Conditionals 4 by Deano (@deangilewicz) on CodePen.

A third way to use a conditional statement is with the switch statement. The switch statement evaluates an expression, matching the expression’s value to a case clause, and executes statements associated with that case.

See the Pen thecodelog.com - JS Conditionals 5 by Deano (@deangilewicz) on CodePen.