This is the fourth day of my participation in the August More text Challenge. For details, see: August More Text Challenge
Consolidate the basic knowledge of learning JavaScript, deepen the understanding of memory, to build a firm foundation! Come on!
With their own understanding, simple and comprehensive summary of basic knowledge, most of the content is the vernacular content, the foundation in the foundation to deepen understanding!
For more detailed learning – it is recommended to view the MDN-javascript documentation, (Little Red Book/White Paper/Blue Book /..) Learn to advance!
Read more: Previous update review
Day1 (1)
Day1 (2)
【 Re-learn JS】 Study every day to consolidate the foundation day2
Preheat the text – Continue to comb through the knowledge
1, switch switch statement
Grammatical structure:
switch(Expression){caseConstant expressions: statements;caseConstant expressions: statements; .default: statement; }Copy the code
Description:
- 1. An expression is usually a variable or an expression, but it must have a specific value
- 2. Execution logic: The value of an expression is compared to a constant expression following a case. If a case satisfies the same value, it automatically executes that case and all subsequent statements
- 3, Resolve case penetration: add a break after the case statement
- 4. Default can be omitted
- 5. If the switch does a congruent comparison === First compare the type and then the value
- 6. The default position can be moved to the front of case
2. Switch nesting
As follows:
switch(Expression){caseConstants:switch() {}}Copy the code
3. Application scenarios of switch and IF
-
When the condition is specific, switch is recommended
-
If else if() is recommended when the condition is a range.
4. Choose structure
Process control Statement:
if(range){expression... }else if(){expression... }switch(fixed value){expression... }Copy the code
5, while
5.1 Cycle: Doing something over and over again
While loop: when loop
5.2 Grammatical structure:
while(Condition) {loop body}Copy the code
5.3 Five elements of the cycle:
- 1. Loop variables
- 2. Initial value of loop variable
- 3. Final value of cyclic variable (cyclic condition)
- 4. Increment of loop variable (step size)
- 5. Circular body (something that is done repeatedly)
5.4 Execution logic:
6, do… while
Do-while: till loop
6.1 Grammatical structure:
do{circular body}while(conditions)Copy the code
6.2 do-while
Execute logic:
6.3 while
和 do... while
The difference between:
While: judge the condition first, while executing the body of the loop, the body may not execute the do at all… The body of the loop must be executed at least once to determine the condition
var i = 10
while (i > 11) {
alert(i)
i++
}
alert(i) / / 10
Copy the code
var i = 10
do {
alert(i) / / 10
i++
} while (i > 11)
alert(i) / / 11
Copy the code
6.4 do-while
Type of problem to be solved by loop:
- Output the topic
- Cycle sum
- How many odd numbers are there within 1–100?
- Output graph problem
7, for loop (for… In)
7.1 Grammatical structure:
for(expression1; expression2; expression3) {loop body}Copy the code
Expression 1: Generally, an initial value is assigned to a loop variable
Expression 2: general cyclic condition
Expression 3: Loop variable increment (step size)
7.2 execution logic :(same as the while loop)
8, break and continue
continue
: Ends this loop and continues to execute the next loopcontinue
It can only be used in cyclic structuresbreak
: interrupts to end this layer’s loopbreak
Used inswitch
Or in a loop
9. Endless loop
Conditions are always established, will form an infinite loop, will always be implemented, avoid!
Use scenarios for while and for
- Recommended if the number of cycles is specified
for
- If the number of cycles is not specified, use it
while
Come on, dreamers
Learning is a continuous process, stick to it, there will be harvest!
Accumulate over a long period of time, consolidate the foundation, early into dafang!
Calm Down & Carry On!
It is not easy to insist, adhere to a long time is not easy