if ternario javascript code example
Example 1: 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 2: expresiones ternarias javascript
var condition = false;
var result1 = "First result";
var result2 = "Second result";
var result = condition ? result1 : result2;
Example 3: examples of Conditional Operator js
var age = 19;
var canDrive = age > 16 ? 'yes' : 'no';
Example 4: ternary operator if javascript
condition ? exprIfTrue : exprIfFalse