javascript ternary operator code example
Example 1: if statement shorthand c
if (true)
printf("This is the shorthand");
// OR
(true) ? (/*run if true*/) : (/*run if false*/);
Example 2: ternary operator
(condition) ? (if true, do this) : (otherwise, do this)
Example 3: conditional operator
var age = 26;
var beverage = (age >= 21) ? "Beer" : "Juice";
console.log(beverage); // "Beer"