Articles → JavaScript → If-Else In Javascript

If-Else In Javascript






Purpose





Syntax


if (condition is true)
{
    //	Execute the code
}
else
{
    // Execute other code
}



Example




var age = 25;
if (age < 18) {
	alert("adolescent");
} else {
	alert("Adult");
}

Try It




If-Else-If




if(condition is true)
{
//	Execute the code
}
else if(condition is true)
{
	// Execute this code
}
else
{
	// Execute this code
}





Posted By  -  Karan Gupta
 
Posted On  -  Monday, March 21, 2011

Query/Feedback


Your Email Id
 
Subject
 
Query/FeedbackCharacters remaining 250