javascript short if else statement code example
Example 1: shorthand if statment in js
isLoggedIn ? "Logout" : "Login";
Example 2: typescript if then shorthand
const x = true;
var result = x === true ? "passed" : "failed";
Example 3: shorthand if statement js
const answer = x > 10 ? "greater than 10" : "less than 10";
if (something)
return;
Example 4: single if statement js true false
condition ? exprIfTrue : exprIfFalse
Example 5: ternary operator javascript
condition ? exprIfTrue : exprIfFalse
let age = 26;
let beverage = (age >= 21) ? "Beer" : "Juice";
console.log(beverage);