About Lesson
Ternary Operator
The ternary operator is a shorthand way of writing an if-else statement. It takes three operands: a condition, a value if true, and a value if false.
Syntax:
JavaScript
condition ? expressionIfTrue : expressionIfFalse;
Example:
JavaScript
let isMember = true;
let discount = isMember ? 20 : 0;
console.log(discount); // 20 if true, 0 if false