The Conditional (Ternary) Operator
If the variable age is a value below 18, the value of the variable voteable will be "Too young", otherwise the value of voteable will be "Old enough".
Description
The conditional operator is a shorthand for writing conditional
if...else
statements.
It is called a ternary operator because it takes three operands.
Syntax
(condition) ? value1:value2
Learn More:
Browser Support
() ? x : y
is an ECMAScript1 (JavaScript 1997) feature.
It is supported in all browsers:
Chrome | Edge | Firefox | Safari | Opera |