Answers for "ternary conditional"

C
15

javascript if shorthand

condition ? doThisIfTrue : doThisIfFalse

1 > 2 ? console.log(true) : console.log(false)
// returns false
Posted by: Guest on May-21-2020
2

The conditional (ternary) operator with three condition

String year = credits < 30 ? "freshman" : credits <= 59 ? "sophomore" : credits <= 89 ? "junior" : "senior";
Posted by: Guest on March-26-2020
4

Ternary Operator

condition ? expression-if-true : expression-if-false;

function findGreater(a, b) {
  return a > b ? "a is greater" : "b is greater";
}
Posted by: Guest on December-28-2020
0

conditional (ternary) operator function parameter

serveDrink(userIsYoungerThan4 ? 'Milk' : userIsYoungerThan21 ? 'Grape Juice' : 'Wine');
Posted by: Guest on October-17-2021
0

conditional (ternary) operator function parameter

//Instead of:
var welcomeMessage  = 'Hello ' + (username ? username : 'guest');

//Can use:
var welcomeMessage  = 'Hello ' + (username || 'guest');
Posted by: Guest on October-17-2021

Code answers related to "C"

Browse Popular Code Answers by Language