Q. Among the following, which one is a ternary operator?
β
Correct Answer: (A)
?:
Explanation:
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".