K

Kirti • 10.45K Points
Tutor II

Q. A conditional expression is also called a 

  • (A) If-then-else statement
  • (B) Alternative to if-else
  • (C) Immediate if
  • (D) All of above
  • Correct Answer - Option(C)
  • Views: 144
  • Filed under category JavaScript

Explanation by: Mr. Dubey

A conditional expression in JavaScript refers to the ternary operator (? :), which is also known as the "immediate if" because it provides a quick, one-line alternative to an if-else statement.

Syntax of Ternary Operator:

condition ? expression1 : expression2;
  • If condition is true, expression1 executes.
  • If condition is false, expression2 executes.

Example:

let age = 18;
let canVote = (age >= 18) ? "Yes" : "No";
console.log(canVote); // Output: "Yes"

Why Not Other Options?

  • (A) If-then-else statement → Incorrect. The ternary operator is not a full if-else statement but a single expression.
  • (B) Alternative to if-else → Partially correct, but the ternary operator is a shortened version of if-else, not an exact alternative in all cases.
  • (D) All of the above → Incorrect. Since A and B are not fully correct, this option is also incorrect.

You must be Logged in to update hint/solution

Discusssion

Login to discuss.

Be the first to start discuss.


Question analytics