conditional javascript ternary code example
Example 1: js ternary
condition ? ifTrue : ifFalse
Example 2: 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 3: ternary operator if javascript
condition ? exprIfTrue : exprIfFalse
Example 4: how to use ternary operator in javascript
var age = 26;
var beverage = (age >= 21) ? "Beer" : "Juice";
console.log(beverage);
Example 5: js ternary if else
ternary if else example