This section provides quick descriptions of different flavors of conditional 'if' statements.
"if" statements are called conditional statements.
An "if" statement allows you to create one or more statement blocks.
The execution flow will be controlled to go through one of those blocks or no block at all, based on conditions
specified in the statement.
JavaScript supports 4 flavors of "if" statements:
1. Single-statement "if":
if (condition) statement;
where "condition" is a Boolean value, and "statement" is a regular statement.
The specified statement will be executed, if and only if the specified condition is "true".
2. Multi-statement "if":
if (condition) {
statement_1;
statement_2;
...
}
The specified multiple statements, a statement block, will be executed,
if and only if the specified condition is "true".
3. "if ... else" Statement:
if (condition)
statement or statement block
else
statement or statement block
Two statements or statement blocks are specified.
But only one of them will be executed based on the value of the specified condition.
If the specified condition is "true", the first statement or statement block will be executed.
If the specified condition is "false", the second statement or statement block will be executed.
4. "if ... else if" Statement:
if (condition_1)
statement or statement block
else if (condition_2)
statement or statement block
...
...
else
statement or statement block
Many statements or statement blocks are specified.
But only one of them will be executed based on the value of the condition specified for that block.
A tutorial example will be given in the next section showing examples of different types of "if" statements.