The if Statement
Use the if statement to specify a block of JavaScript code to be executed if a condition is true.
if (condition) {
block of code to be executed if the condition is true
}
The else Statement
Use the else statement to specify a block of code to be executed if the condition is false.
if (condition) {
block of code to be executed if the condition is true
} else {
block of code to be executed if the condition is false
}
The else if Statement
Use the else if statement to specify a new condition if the first condition is false.
if (condition1) {
block of code to be executed if condition1 is true
} else if (condition2) {
block of code to be executed if the condition1 is false and condition2 is true
} else {
block of code to be executed if the condition1 is false and condition2 is false
}
The JavaScript Switch Statement
Use the switch statement to select one of many blocks of code to be executed.
switch(expression) {
case n:
code block
break;
case n:
code block
break;
default:
default code block
}
Javascript Conditions
Action to Be Performed
![](https://static.wixstatic.com/media/be0c68_dc7ffcd36c3749e497516083faa69986.png/v1/fill/w_152,h_152,al_c,q_85,usm_0.66_1.00_0.01,enc_avif,quality_auto/be0c68_dc7ffcd36c3749e497516083faa69986.png)