H I O X INDIA
Javascript Tutorial
Google
Web hscripts.com
 HOME  ||  Scripts  ||  Purchase  ||  Tutorials  ||  Images  ||  Tools  ||  Directories 
  :-)  Send Page   :-)   Feedback   :-)   Register   :-)   Links   :-)   Support   :-)   Bookmarks :-)  
 Forums   Hosting   Internet Stats   Easy Calculation   FUN Games 

Java-Script Tutorial
Introduction
Variables
Operators
Statements
Loops
Functions
Objects
Arrays
Browser Objects
Form DOM
Ask Your Doubts
Feedback





If Statement Code


Topic

How to validate a condition in javascript?
What is the use of if statement?



Explanation

If Statement:
        If statement is used to check or verify a condition and execute a set of statement only if the condition is true. This should be referred as a statement and not as a function.

Syntax:
if(condition)
{
     // set of statements that will be executed
     // only if the condition is true or satisfied
}


Example Code:
<script language="javascript">
var a = "if check";
if(a == "if check")
{
document.write(" inside if statement ");
}
</script>


Result:

In the above example the condition is to check whether variable 'a' equals (==) the string "if check". As the condition satisfies, the statements inside the brackets are executed.

Nested If:
        Nested if statement is nothing but using an if statement inside another if statement. Nested if is used when we check a condition only when another condition is true. For an example when we purchase a car, first we verify is the car looks good, only if it satisfies we go to the next condition color, then next and so on..

Syntax: Nested if
if(condition 1)
{
     if(condition 2)
      {
     // set of statements that will be executed
      }
}




        Javascript (JS) is one of the most used languages in the world. Some times spelled as Java Script. Hope you enjoy this tutorial. Do send your feedback or suggestions on this javascript or java script tutorial. This is a copyright content.

others

privacy policy     license     sitemap
© 2004-2005 HIOX INDIA - hioxindia.com

Other Links