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");
}