A

Admin • 828.03K Points
Coach

Q. Among the following, which one is a ternary operator?

  • (A) ?:
  • (B) -
  • (C) :
  • (D) +
  • Correct Answer - Option(A)
  • Views: 5
  • Filed under category JavaScript
  • Hashtags:

Explanation by: Admin

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

Discusssion

Login to discuss.

Be the first to start discuss.