ternary operator in ternary operator code example
Example 1: ternary operator
(condition) ? (if true, do this) : (otherwise, do this)
Example 2: ternary operator
const hasAccount = true
const userDisplayMessage = hasAccount ? 'Welcome Back' : 'Please Sign Up'
console.log(userDisplayMessage)
Example 3: ternary operator
condition ? console.log("true") : console.log("false");
let n = 15;
n % 2 === 0 ? console.log("even number") : console.log("odd number");
Example 4: ternary operator
isMember ? '$2.00' : '$10.00'