Flow control is about controlling the conditions under which the statements in your program execute. If/else is the most common flow control construct that you will be using. Both PHP and Javascript support this kind of statement. The if/else statement is called a compound statement. Compound statement are enclosed in curly brackets:
{
var num = 0;
var str = 'Hello world!';
var booln = true;
}
The if/else statement is made of two compound statements. In particular, the if/else statement is used to execute a block of code based on a condition. The condition is made of a comparison operation. This kind of expression evaluates to a boolean value, if you remember from the last blog. The if/else statement executes one block of code if the expression evaluates to true and another if the expression evaluates to false. The syntax of the if/else statement:
var truth_value = true;
if(truth_value == true){
truth_value;
}else{
truth_value = false;
}
A compound comparison expression can be made by using the logical operators along with the comparison operators. The logical operators are AND(&&), OR(||), and NOT(!). Parenthesis can be used to group the simple expressions.
var truth_value = true;
if( (truth_value == true) && (truth_value != false) ){
truth_value;
}else{
truth_value = false;
}