Javascript - Operator Conditional Operator

Introduction

The conditional operator has the following form:

variable = boolean_expression ? true_value : false_value; 

If it's true, then true_value is assigned to the variable; if it's false, then false_value is assigned to the variable:

var max = (num1 > num2) ? num1 : num2; 

In this example, max is to be assigned the number with the highest value.

The expression states that if num1 is greater than num2, then num1 is assigned to max.

If the expression is false, then num2 is assigned to max.

Exercise