xxxxxxxxxx
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"
xxxxxxxxxx
String year = credits < 30 ? "freshman" : credits <= 59 ? "sophomore" : credits <= 89 ? "junior" : "senior";
xxxxxxxxxx
serveDrink(userIsYoungerThan4 ? 'Milk' : userIsYoungerThan21 ? 'Grape Juice' : 'Wine');
xxxxxxxxxx
function checkEqual(a, b)
{
return a === b ? “Equal” : “Not Equal” ;
}
checkEqual(1, 2);
xxxxxxxxxx
function example() {
return condition1 ? value1
: condition2 ? value2
: condition3 ? value3
: value4;
}
xxxxxxxxxx
//Instead of:
var welcomeMessage = 'Hello ' + (username ? username : 'guest');
//Can use:
var welcomeMessage = 'Hello ' + (username || 'guest');