Chapter 4 Statement
Formally, a statement is a piece of code that ends with a semicolon. Whether this code is an expression, something else, or even nothing, as long as it ends with a semicolon, it can be considered a statement.
Functionally, a statement implies the meaning of "making something happen" (make something happen).
By enclosing multiple statements in curly braces, a compound statement (statement block) is formed.
JavaScript programs is nothing more than a sequence of statements to execute.
1. Condition condition
1.1 If statement
1.2 Switch statement
switch (expression) {
Case Value-1:statement
break;
Case Value-2:statement
break;
Default:statement
}
If you omit a break, it means merging two scenarios.
Value can also be a Boolean expression.
2. Loop loops
2.1 While Statement
Front-facing detection.
2.2 Do-while Statements
After detection, the code will be executed at least once.
2.3 For statement
2.4 for-in Statements
The property used to enumerate objects.
For (Val in object) {}
The statement iterates through the properties of the object and assigns the property name to Val in turn.
JavaScript built-in object properties are not enumerable.
If a property value exists with null or undefined, the loop terminates. It is therefore better to test before using for-in.
3, Jump Jumps
3.1 Label statement
A label can be used to represent a loop, similar to a variable, and then used in conjunction with break or continue to implement nesting loops in a loop.
3.2 break&continue
Controls the execution flow of code in a loop.
Break exits the loop immediately.
Continue also exits the loop immediately, and then the loop continues to execute from the top. Continue to express the meaning of "skip the next step, go straight to the following cycle".
3.3 Return
Used to specify the return value after a function call. It can only be used in functions.
3.4 Throw
Throws an error, stops execution of the current code, jumps to the nearest exception handler.
Exception handlers: try/catch/finally
Attached: JavaScript statement list
Kidney Day Arch A stroke JavaScript series CHAPTER4 statements