1. What are expressions and statements
1.1 expression
- The 1+2 expression has the value 3
- The value of the add(1,2) expression is the return value of the function
1.2 the statement
Var a = 1 is a statement
1.3 Differences between the two
- Expressions generally have values, and statements may or may not have values
- Statements generally change the environment (declaration, assignment)
2. Rules for identifiers
2.1 Naming Rules
- The first character can be a Unicode letter or $or _ or Chinese
- The following characters, in addition to the above, can also be numbers
2.2 pay attention to
- At most, there are two underscores, and then I can’t count them
- Prefer to use Chinese, do not use Chinese pinyin, because programmers pinyin may be different
3. If the else statement
3.1 grammar
If (expression){statement 1}else{statement 2}
- If the expression is true, statement 1 is executed; If the expression is false, statement 2 is executed
{} can be omitted only if the statement is one line long, but this is not recommended
3.2 Recommended writing method
- The most recommended way to write it
If (expression){statement}else if(expression){statement}else{statement}
- This is recommended
Funtion fn(){if(expression){return expression}if expression){return expression} return expression}
4. While for statement
4.1 while
While (expression){statement}
- Judge the expression is true or false, when the expression is true, execute the statement, execute the expression is true or false; When the expression is false, we jump out of the loop and execute the statement following the while
- For example,
4.2 the for
For (statements 1; Expression is 2; Statement 3){body of loop}
- Execute statement 1 once, then check expression 2, if true, execute the body of the loop, then execute statement 3, then check expression 2; If false, execute the statement following the for loop
- For example,
5.break continue
5.1 break
Break Exits all loops except one
5.2 the continue
Continue Exits a loop
6.label
Label: statement