conditional operator with two parameters javascript code example
Example 1: ternary operator javascript
let age = 15;
let canDrive = age >= 16 ? 'yes' : 'no';
let age = 15;
let canDrive;
if (age >= 16) {
canDrive = 'yes';
} else {
canDrive = 'no';
}
Example 2: javascript ternary
condition ? doThisIfTrue : doThisIfFalse
1 > 2 ? console.log(true) : console.log(false)
Example 3: The conditional (ternary) operator with three condition
String year = credits < 30 ? "freshman" : credits <= 59 ? "sophomore" : credits <= 89 ? "junior" : "senior";