Operators
Conditional operator (? :)
Tests the truthiness of the first expression and evaluates only the selected result expression. The result is the value of that branch. Nested conditionals group to the right.
Formal Syntax & Structure
javascript syntaxjavascript
test ? consequent : alternateParameters & Attributes
| Name | Type | Description |
|---|---|---|
| test | expression | Value tested for truthiness. |
| consequent | expression | Evaluated for a truthy test. |
| alternate | expression | Evaluated for a falsy test. |
Return Value
selected value
Value of the selected expression.
Working Example
Example Snippetjavascript
console.log(3 > 2 ? "yes" : "no");