Ternary Operator

Noun · Development

Definitions

  1. A concise conditional expression with the syntax `condition ? valueIfTrue : valueIfFalse` that evaluates to one of two values based on a boolean condition — an inline alternative to an if-else block that returns a value rather than executing statements.

    In plain English: A shorthand way to write 'if this, then that, otherwise the other thing' in a single line of code.

    Example: "Use the ternary operator for the label: `isAdmin ? 'Admin' : 'User'` — no need for a whole if-else for a single assignment."

Related Terms