Ternary Operator

noun

say it: “TER-nuh-ree OP-er-ay-ter” /ˈtɜːrnəri ˈɒpəreɪtər/

The ? : operator, read "if, then, else": condition ? valueIfTrue : valueIfFalse picks one of two values in one line.

What does Ternary Operator do in JavaScript?

Ternary Operator — The ?: operator, which chooses one of two values from a condition.

const label = stock > 0 ? "Available" : "Sold out";

In a sentence

  • “The ternary operator in isOpen ? "Open" : "Closed" picks the word for the shop sign.”

Level: Apprentice · More JavaScript terms at this level

Updated

In other subjects