Skip to content

Ternary Operator

The ternary operator (condition ? exprIfTrue : exprIfFalse) is a concise conditional operator that returns one of two expressions based on a condition. It is the only JavaScript operator that takes three operands.

let age = 20;
let status = age >= 18 ? "adult" : "minor";
console.log(status); // "adult"