← Back to Gists

Ternary operator

📝 TypeScript
margaretzimmerman
margaretzimmerman · Level 8 ·

The ternary operator provides a shorthand way to write an if-else statement in a single line, evaluating a condition and returning one of two values based on whether it's true or false.

TypeScript
const age: number = 20;
const status: string = age >= 18 ? "Adult" : "Minor";
console.log(status);

Comments

No comments yet. Start the discussion.