Der bedingte (ternäre) Operator mit drei Bedingungen
String year = credits < 30 ? "freshman" : credits <= 59 ? "sophomore" : credits <= 89 ? "junior" : "senior";
Lazy Louse
String year = credits < 30 ? "freshman" : credits <= 59 ? "sophomore" : credits <= 89 ? "junior" : "senior";
condition ? expression-if-true : expression-if-false;
function findGreater(a, b) {
return a > b ? "a is greater" : "b is greater";
}
function getFee(isMember) {
return (isMember ? '$2.00' : '$10.00');
}
console.log(getFee(true));
// expected output: "$2.00"
console.log(getFee(false));
// expected output: "$10.00"
console.log(getFee(null));
// expected output: "$10.00"
serveDrink(userIsYoungerThan4 ? 'Milk' : userIsYoungerThan21 ? 'Grape Juice' : 'Wine');
function checkEqual(a, b)
{
return a === b ? “Equal” : “Not Equal” ;
}
checkEqual(1, 2);
//Instead of:
var welcomeMessage = 'Hello ' + (username ? username : 'guest');
//Can use:
var welcomeMessage = 'Hello ' + (username || 'guest');