top of page

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

bottom of page