Articles → JavaScript → if-else in JavaScript

if-else in JavaScript







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




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






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




var age = 25;
if (age < 18) {
	alert("adolescent");
} else if (age > 18 && age < 50) {
	alert("Young");
} else {
	alert("Old");
}





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

Query/Feedback


Your Email Id  
 
Subject 
 
Query/FeedbackCharacters remaining 250