Conditionals and Logic
Ternary Choice
Choose a value with a conditional expression.
Ternary Choice
ternary_choice.js
const count = 1;
const noun = count === 1 ? "item" : "items";
const visible = count > 0 ? "show" : "hide";
const label = count + " " + noun;
console.log("count=" + count);
console.log("visible=" + visible);
console.log("label=" + label);
ternary-choice
The ternary operator chooses between two expressions and returns the selected value.