If Statement
Syntax 
  if(condition)
  {
       // execute this block if condition is true 
  }
  
  Conditional statements are used to perform different actions based on different  conditions.
  1. If statements are also known as  conditional statements. This simply means that they are able to take action  based on various conditions.
  2. If  statements is used to check whether specified condition is true or  false.
  3. If statements allows the computer to  make decisions based on the values of variables which can take the specified action  based on the input that is given.
Example: 1
<script  type="text/javascript">
  var  num1=20;
  var  num2=30;
  if  (num1<num2)
    {
      alert("This line will show on  browser");
     }
  </script>
Example: 2
<script  type="text/javascript">
  var  num1=20;
  var  num2=30;
  if  (num2<num1)
    {
      alert("This line will not show on  browser");
     }
  </script>
The browser will show the following :
Nothing. Because, the condition is false and 30 is greater than 20.
No comments:
Post a Comment