opérateur ternaire javascript code example
Example 1: ternaire javascript
(isMember ? '$2.00' : '$10.00')
Example 2: ternaire js
(condition ? doIfTrue : doIfFalse)
//exemple :
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"
Example 3: ternary
isMember ? '$2.00' : '$10.00'
// isMember true => output: "$2.00"
// isMember false => output: "$10.00"
// isMember null => output: "$10.00"