The conditional (ternary) operator with three condition
String year = credits < 30 ? "freshman" : credits <= 59 ? "sophomore" : credits <= 89 ? "junior" : "senior";
Source: stackoverflow.com
Use the Conditional (Ternary) Operator
function checkEqual(a, b) { return a === b ? “Equal” : “Not Equal” ; } checkEqual(1, 2);
conditional (ternary) operator function parameter
//Instead of: var welcomeMessage = 'Hello ' + (username ? username : 'guest'); //Can use: var welcomeMessage = 'Hello ' + (username || 'guest');
Source: stackoverflow.com
conditional (ternary) operator function parameter
serveDrink(userIsYoungerThan4 ? 'Milk' : userIsYoungerThan21 ? 'Grape Juice' : 'Wine');
Source: stackoverflow.com