1. What are expressions and statements
expression
1 + 3
An expression, called an expression, is a calculation to get a return value.
statements
- This is a statement, and a statement is an operation to accomplish something, such as a line assignment statement.
var a = 1
2. Rules for identifiers
The first character can be any Unicode letter (including English and other languages), as well as the dollar sign ($) and underscore (_).
In addition to Unicode letters, dollar signs, and underscores, the numbers 0-9 can be used for the second and subsequent characters.
3. If else statement
if
You can have a block of code followed by oneelse
Code block that represents the code to execute if a condition is not met.
if (m === 3) {
// The statement to execute when the condition is met
} else {
// The statement to execute if the condition is not met
}
-
The code above determines whether the variable m is equal to 3 and executes an if block if it is, and else block otherwise.
-
More than the if… Else statements can be joined together.
4. While for statement
The while loop
While
The statement consists of a loop condition and a block of code that executes over and over again as long as the condition is true.
While (condition)
Statements;
/ / or
A while (condition) statement;
The for loop
for
Statements are another form of a loop command that specifies the start, end, and termination conditions of a loop. Its format is as follows.
For (initializes the expression; Conditions; Incrementing expression)
statements
/ / or
For (initializes the expression; Conditions; Incrementing expression) {
statements
}
5. Break the continue statement
break
Statements andcontinue
Statements are jumps that allow code to be executed out of the existing order.break
Statements are used to break out of a code block or loop.continue
Statement is used to immediately terminate the loop, return to the head of the loop structure, and start the next loop.
6. The label statement
- The JavaScript language allows statements to be preceded by labels, which act as locators for jumping to any point in the program
- Tags are usually associated with
break
Statements andcontinue
Statements are used together to break out of a particular loop.