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
}