Explanation:
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.