Directory:

  1. What are process control statements?
  2. The format and use of if statements

What is a process control statement

Statements in JavaScript are executed layer by layer from top to bottom
The flow control statement can control the flow of the program execution, so that the program can choose to execute according to certain conditions.
Conditional statements can be used to determine a statement before it is executed. If the condition is true, the statement is executed. If the condition is not true, the statement is not executed.

The format and use of the if statement

If statement, conditional position, must Boolean value/expression/variable, if not Boolean type, JS will automatically convert
Format:

if(conditional expression){if the condition is true, execute; }else{not set to execute, here; }Copy the code
Format. 2:

if(conditional expression 1){conditional expression 1, execute; }else if(conditional expression 2){conditional expression 2, execute; }else if(conditional expression 3){conditional expression 3, execute; }else{expressions are not valid to execute, here; }Copy the code
Rule: Conditional expressions are evaluated when an if statement is executed.

  • If the conditional expression is true, the statement after if is executed.
  • If the conditional expression is false, the statement after if is not executed.
Case 1:

var age=70
if(age<60){
    alert("Not yet old enough to retire.")}else{
    alert("Retired.")}Copy the code
Case 2:

var age=40;
if(age>17) {
    alert("Come of age")}else if(age>30){
    alert("Middle-aged man.")}else if(age<18){
    alert("Minor")}else{
    alert("Not getting any younger.")}Copy the code

Next: process control statement _switch statement