Condition Checking
 
If statement
 

We can use this statement if we want to execute a set of code in case the given condition is true. Let us say if today is Sunday go to market.

 

syntax (How it is written):

  if (condition)

{

job to be done if condition is found true

}

 
Example
 

<html>

<head>

</head>

<body>

<script type="text/javascript">

var a,b;

a=100

b=50

document.write("<br>Value of a "+a);

document.write("<br>Value of b "+b);

if (a>b)

{

document.write("<br>value of a is greater than b ");

}

</script>

</body>

</html>

 
Understanding program :
Value of a is 100 and value of b is 50. In if statement, we are checking that if a is greater than b then the message should be printed.
 
Output:
 
Value of a 100
Value of b 50
value of a is greater than b
Click here to view result of this program on browser