ECMAScript Conditional Operators
- Previous Page Equality Operators
- Next Page Assignment Operators
Conditional Operator
The conditional operator is the most functional operator in ECMAScript, and its form is the same as in Java.
variable = boolean_expression ? true_value : false_value;
This expression is mainly based on boolean_expression The result of the calculation of the boolean_expression is conditionally assigned to the variable. If Boolean_expression Assign to a variable; if it is true, then assign true_value Assign to a variable; if it is false, then assign false_value Assign to a variable.
For example:
var iMax = (iNum1 > iNum2) ? iNum1 : iNum2;
In this example, iMax will be assigned the maximum value among the numbers. The expression assigns iNum1 to iMax if iNum1 is greater than iNum2. However, if the expression is false (i.e., iNum2 is greater than or equal to iNum1), then iNum2 is assigned to iMax.
- Previous Page Equality Operators
- Next Page Assignment Operators