JavaScript if else statement

Here is how the javascript’s if else statement looks like.

if (condition)
{
     //run this code if condition is true
}
else
{
     //else run this code if the first condition is not true
}

Here is an example of how to use the if else statement.

if (age < 12)
{
  alert("small boy");
}
else if (age < 50)
{
  alert("young man");
}
else
{
  alert("old man");
}

As you can see from the example above if the first condition is true then the code within the first if block will run and the rest of the if block will be skipped. Else if the second condition is true then the second code block will run instead and finally the third code block will run if both the first and second if statements are false.