JavaScript if...else Statements:
While writing a program, there may be a situation when you need to adopt one path out of the given two paths. So you need to make use of conditional statements that allow your program to make correct decisions and perform right actions.JavaScript supports conditional statements which are used to perform different actions based on different conditions. Here we will explain if else statement.
JavaScript supports following forms of if else statement:
·
if statement
·
if else statement
·
if else if statement.
If statement:
The if statement is the fundamental control statement that allows JavaScript to make decisions and execute statements conditionally.Syntax:
if (expression)
{
Statement(s) to be executed if expression is true
}
|
Example:
<script type="text/javascript">
<!--
var age = 20;
if( age > 18 ){
document.write("<b>Qualifies for driving</b>");
}
//-->
</script>
|
No comments:
Post a Comment