Ternary Operator
condition ? expression-if-true : expression-if-false;
function findGreater(a, b) {
return a > b ? "a is greater" : "b is greater";
}
Ternary Operator
condition ? expression-if-true : expression-if-false;
function findGreater(a, b) {
return a > b ? "a is greater" : "b is greater";
}
ternary operator
isMember ? '$2.00' : '$10.00'
// isMember true => output: "$2.00"
// isMember false => output: "$10.00"
// isMember null => output: "$10.00"
How does ternary operator works ?
let moneyAmount = 80;
let creditCardAmont = 70;
let drink = (moneyAmount > 60 && creditCardAmont > 50) ? 'buy coke' : 'filter water';
console.log(drink)
How many operands does a ternary operator have?
<?php
$i = 0;
while ((--$i > ++$i) - 1)
{
print $i;
}
?><?php
$i = 2;
while (++$i)
{
while ($i-- > 0)
print $i;
}
?>
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us