if else conditional statement in Javascript
Code snippet on how to if else conditional statement in Javascript
if (condition) {
// code block to be executed if condition is true
} else {
// code block to be executed if condition is false
}
This code is an if-else statement in Javascript. This statement begins with the keyword ‘if’ followed by a condition in parentheses. If the condition evaluates to true, the code block inside the first set of curly brackets will be executed. Otherwise, the code block inside the second set of curly brackets will be executed. This code will compare the condition to a Boolean value, that is, true or false. If the condition is true, the code in the if block will execute; otherwise, the code in the else block will execute.