http://www.tutorialspoint.com/javascript/javascript_ifelse.htm
Copyright © tutorialspoint.com
JAVASCRIPT - IF...ELSE STATEMENT
JAVASCRIPT - IF...ELSE STATEMENT
While writing a program, there may be a situation when you need to adopt one out of a given set
of paths. In such cases, you need to use conditional statements that allow your program to make
correct decisions and perform right actions.
JavaScript supports conditional statements which are used to perform different actions based on
different conditions. Here we will explain the if..else statement.
Flow Chart of if-else
The following flow chart shows how the if-else statement works.
JavaScript supports the following forms of if..else statement −
if statement
if...else statement
if...else if... statement.
if statement
The if statement is the fundamental control statement that allows JavaScript to make decisions
and execute statements conditionally.
Syntax
The syntax for a basic if statement is as follows −
Here a JavaScript expression is evaluated. If the resulting value is true, the given statements are
executed. If the expression is false, then no statement would be not executed. Most of the times,
you will use comparison operators while making decisions.
Example