How do you write a conditional statement in JavaScript?

How do you write a conditional statement in JavaScript?

a) if (condition) { … }
b) check (condition) { … }
c) when (condition) { … }
d) condition (if) { … }

Answer:

a) if (condition) { … }

Explanation:

In JavaScript, a conditional statement is written using if. It checks a condition and executes the code block if the condition is true.

Example:


if (x > 10) {
    console.log("x is greater than 10");
} else {
    console.log("x is not greater than 10");
}
    

Reference:

JavaScript MCQ (Multiple-Choice Questions)

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top