what is a ternary operator code example
Example 1: if statement shorthand c
if (true)
printf("This is the shorthand");
(true) ? () : ();
Example 2: js ternary
condition ? ifTrue : ifFalse
Example 3: ternary operator
(condition) ? (if true, do this) : (otherwise, do this)
Example 4: ternary operator
const hasAccount = true
const userDisplayMessage = hasAccount ? 'Welcome Back' : 'Please Sign Up'
console.log(userDisplayMessage)
Example 5: 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 6: Ternary Operator
condition ? expression-if-true : expression-if-false;
function findGreater(a, b) {
return a > b ? "a is greater" : "b is greater";
}