js ternary operator else if code example
Example 1: how to make one line if in js
if (5 > 3) return "Is greater";
let res = (1 > 3) ? "is greater" : "is less than";
Example 2: javascript ternary operator
condition ? doThisIfTrue : doThisIfFalse
let num1 = 1;
let num2 = 2;
num1 < num2 ? console.log("True") : console.log("False");
num1 > num2 ? console.log("True") : console.log("False");
Example 3: javascript ternary
condition ? doThisIfTrue : doThisIfFalse
1 > 2 ? console.log(true) : console.log(false)
Example 4: ternary operator javascript
condition ? exprIfTrue : exprIfFalse
let age = 26;
let beverage = (age >= 21) ? "Beer" : "Juice";
console.log(beverage);
Example 5: js ternary if else
ternary if else example