Conditions:

Java Script supports conditional statements which are used to perform different actions based on different conditions. 

IF Statement:

If the condition is true then the statements in the block will execute.
syntax:
if (condition/expression) {
//statements
}

IF Else Statement:
If the condition is true then if block will execute, If it is false then else block will execute.
Syntax:
If (expression) {
 //statements
}
else {
 //statements
}

Else IF Statement:
If number of conditions are more then the else if ladder is best to make decision.
Syntax:
If (expression) {
 //statements
}
else if {
 //statements
}
else {
 //statements
}

Example1:
Code:

Output:

If the name is changed to another name then output is:

Example2:
Code:


Output:

Example 3:
Code:


Output:





Switch case:

1) The value of expression is compared with each case.
2) The matched block will be executed.
3) Break keyword is used to stop the execution.
4) If the value is not matched with the case then default case will execute.
Syntax:
switch(expression)
{
case x1: //statement 1;
break;
case x2: //statement 2;
break;
default: //statement;
}

Code:


Output:



Control loops:

If the same code need to execute number of times then we will use control loops.

For Loop:
If we don't know how many times the code will execute then for loop is preferable.
If the condition is true then the block of statements will execute.If the condition is false then the loop terminate.

Code:


Output:


Using break keyword:

Output:


While Loop:

If we know how many times the code will execute then while loop is preferable.
If the condition is true then the block of statements will execute.If the condition is false then the loop terminate.

Code:

Output: