JavaScript ternary
condition ? doThisIfTrue : doThisIfFalse
1 > 2 ? console.log(true) : console.log(false)
// returns false
Adventurous Ant
condition ? doThisIfTrue : doThisIfFalse
1 > 2 ? console.log(true) : console.log(false)
// returns false
// ternary operator in javascript
const x = 6;
let answer = x > 10 ? "greater than 10" : "less than 10";
console.log(answer);
// output: less than 10
// nested condition
const answer = x > 10 ? "greater than 10" : x < 5 ? "less than 5" : "between 5 and 10";
console.log(answer);
// output: between 5 and 10
// Syntax
condition ? ifTrue : ifFalse
var variable1 = typeof variable1 !== 'undefined' ? variable1 : default_value;