how to use multiple ternary operator in javascript code example
Example 1: js ternary else if multi
var foo = (
bar === 'a' ? 1 :
bar === 'b' ? 2 :
bar === 'c' ? 3 :
null
);
Example 2: javascript ternary operator
condition ? doThisIfTrue : doThisIfFalse
let num1 = 1;
let num2 = 2;
num1 < num2 ? console.log("True") : console.log("False");
num1 > num2 ? console.log("True") : console.log("False");
Example 3: multiple ternary operator javascript
var icon = (area == 1) ? icon1 : (area == 2) ? icon2 : icon0;