js_tutorial

Javascript Output

Javascript Output Qualifies for driving Set the variable to different value and then try... if...else Statement The ‘if...else’ statement is the next form of control statement that allows JavaScript to execute statements in a more controlled way. Syntax The syntax of an if-else statement is as follows: if (expression){ }else{ } Statement(s) to be executed if expression is true Statement(s) to be executed if expression is false Here JavaScript expression is evaluated. If the resulting value is true, the given statement(s) in the ‘if’ block, are executed. If the expression is false, then the given statement(s) in the else block are executed. Example Try the following code to learn how to implement an if-else statement in JavaScript.

Javascript //--> Set the variable to different value and then try... Output Does not qualify for driving Set the variable to different value and then try... if...else if... Statement The ‘if...else if...’ statement is an advanced form of if…else that allows JavaScript to make a correct decision out of several conditions. Syntax The syntax of an if-else-if statement is as follows: if (expression 1){ Statement(s) to be executed if expression 1 is true }else if (expression 2){ Statement(s) to be executed if expression 2 is true }else if (expression 3){ }else{ } Statement(s) to be executed if expression 3 is true Statement(s) to be executed if no expression is true There is nothing special about this code. It is just a series of if statements, where each if is a part of the else clause of the previous statement. Statement(s) are executed based on the true condition, if none of the conditions is true, then the else block is executed. Example 41