ternary operators in javascript code example
Example 1: js ternary
condition ? ifTrue : ifFalse
Example 2: javascript ternary
age >= 18 ? `wine` : `water`;
Example 3: javascript ternary operator
var isOpen = true;
var welcomeMessage = isOpen ? "We are open, come on in." : "Sorry, we are closed.";
Example 4: ternary operator javascript
let age = 15;
let canDrive = age >= 16 ? 'yes' : 'no';
let age = 15;
let canDrive;
if (age >= 16) {
canDrive = 'yes';
} else {
canDrive = 'no';
}
Example 5: ternary operator in javascript
FullName: (obj.FirstName && obj.LastName) ? obj.FirstName + " " + obj.LastName : "missing values",