Conditional statements are used to decide the flow of execution based on different conditions. If a condition is true, you can perform one action and if the condition is false, you can perform anothe.
Statement that is executed if condition is falsy and the else clause exists. Can be any statement, including block statements and further nested if statements. Description.
An if statement can be followed by an optional else if.else statement, which is very useful to test various conditions using single if.else if statement. When using if, else if, else statements there are a few points to keep in mind. An if can have zero or one else's and it must come after any else if's. An if can have zero to many else if.
Conditional operators: if, '?' Sometimes, we need to perform different actions based on different conditions. To do that, we can use the if statement and the conditional operator ?, that’s also called a “question mark” operator.
How if statement works? The if statement evaluates the test expression inside the parenthesis (). If the test expression is evaluated to true, statements inside the body of if are executed.; If the test expression is evaluated to false, statements inside the body of if are not executed.; To learn more about when test expression is evaluated to true (non-zero value) and false (0), check.