
Statement(s) are executed based on the true condition, if none of the conditions is true, then the else block is executed. It is just a series of if statements, where each if is a part of the else clause of the previous statement. There is nothing special about this code. Statement(s) to be executed if no expression is true

Statement(s) to be executed if expression 3 is true Statement(s) to be executed if expression 2 is true Statement(s) to be executed if expression 1 is true The syntax of an if-else-if statement is as follows − statement is an advanced form of if…else that allows JavaScript to make a correct decision out of several conditions. Set the variable to different value and then try. Try the following example to understand how the if statement works.ĭocument.write("Does not qualify for driving") Most of the times, you will use comparison operators while making decisions. If the expression is false, then no statement would be not executed.

If the resulting value is true, the given statement(s) are executed. Here a JavaScript expression is evaluated. Statement(s) to be executed if expression is true The syntax for a basic if statement is as follows − The if statement is the fundamental control statement that allows JavaScript to make decisions and execute statements conditionally. JavaScript supports the following forms of if.else statement − The following flow chart shows how the if-else statement works. Here we will explain the if.else statement.

JavaScript supports conditional statements which are used to perform different actions based on different conditions. In such cases, you need to use conditional statements that allow your program to make correct decisions and perform right actions. While writing a program, there may be a situation when you need to adopt one out of a given set of paths.
