- Home
- /
- Tutorials
- /
- JavaScript Tutorial
- /
- JavaScript Ternary Operator
JavaScript Conditions
JavaScript Ternary Operator
The ternary operator is a short way to choose between two values.
It is the only JavaScript operator that takes three parts, which is where the name comes from.
It is an expression, so it produces a value you can assign or return.
Example
Example
javascript
const age = 20;
const status = age >= 18 ? "adult" : "minor";
console.log(status);The output is adult.
The Three Parts
A condition, then a question mark.
The value to use when the condition is true.
