The Conditional Operator in JavaScript
The conditional operator is the only JavaScript operator that takes three operands. The operator can have one of two values based on a condition. The syntax is:
condition ? val1 : val2
If condition is true, the operator has the value of val1. Otherwise it has the value of val2. You can use the conditional operator anywhere you would use a standard operator.
For example,
status = (age >= 18) ? “adult” : “minor”
Leave a Reply