ternary if code example
Example 1: javascript ternary operator
var isOpen = true;
var welcomeMessage = isOpen ? "We are open, come on in." : "Sorry, we are closed.";
Example 2: Ternary Operator
condition ? expression-if-true : expression-if-false;
function findGreater(a, b) {
return a > b ? "a is greater" : "b is greater";
}
Example 3: ternary operator in javascript
FullName: (obj.FirstName && obj.LastName) ? obj.FirstName + " " + obj.LastName : "missing values",
Example 4: ternary operator javascript
condition ? exprIfTrue : exprIfFalse
let age = 26;
let beverage = (age >= 21) ? "Beer" : "Juice";
console.log(beverage);