A
Q. Among the following, which one is a ternary operator?
- Correct Answer - Option(A)
- Views: 5
- Filed under category JavaScript
- Hashtags:
A
The ?: operator is known as the ternary operator, and it is a shorthand for an if-else statement. It takes three operands:
condition ? expression_if_true : expression_if_false;
For example:
let result = (x > 10) ? "Greater" : "Smaller";
This means that if x > 10 is true, result will be "Greater", otherwise, it will be "Smaller".
You must be Logged in to update hint/solution
Be the first to start discuss.
Discusssion
Login to discuss.