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
πŸ’¬ Discuss
βœ… Correct Answer: (C) Immediate if
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.
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.

πŸ’¬ Discussion


πŸ“Š Question Analytics

πŸ‘οΈ
221
Total Visits
πŸ“½οΈ
4 y ago
Published
πŸŽ–οΈ
Kirti
Publisher
πŸ“ˆ
96%
Success Rate