Friday, 14 March 2014

IF ELSE STATEMENT



If else statement:

The if...else statement is the next form of control statement that allows JavaScript to execute statements in more controlled way.

Syntax:

if (expression)
{
   Statement(s) to be executed if expression is true
}
else
{
   Statement(s) to be executed if expression is false
}
Here JavaScript expression is evaluated. If the resulting value is true, given statement(s) in the if block, are executed. If expression is false then given statement(s) in the else block, are executed.

Example:

<script type="text/JavaScript">
<!--
var age = 15;
if( age > 18 ){
   document.write("<b>Qualifies for driving</b>");
}else{
   document.write("<b>Does not qualify for driving</b>");
}
//-->
</script>

No comments: