MindMap Gallery JS Basics Day2
This is a mind map about the basics of JS Day 2, which summarizes operators, statements, etc. Hope this mind map helps you!
Edited at 2024-01-18 10:21:22This is a mind map about bacteria, and its main contents include: overview, morphology, types, structure, reproduction, distribution, application, and expansion. The summary is comprehensive and meticulous, suitable as review materials.
This is a mind map about plant asexual reproduction, and its main contents include: concept, spore reproduction, vegetative reproduction, tissue culture, and buds. The summary is comprehensive and meticulous, suitable as review materials.
This is a mind map about the reproductive development of animals, and its main contents include: insects, frogs, birds, sexual reproduction, and asexual reproduction. The summary is comprehensive and meticulous, suitable as review materials.
This is a mind map about bacteria, and its main contents include: overview, morphology, types, structure, reproduction, distribution, application, and expansion. The summary is comprehensive and meticulous, suitable as review materials.
This is a mind map about plant asexual reproduction, and its main contents include: concept, spore reproduction, vegetative reproduction, tissue culture, and buds. The summary is comprehensive and meticulous, suitable as review materials.
This is a mind map about the reproductive development of animals, and its main contents include: insects, frogs, birds, sexual reproduction, and asexual reproduction. The summary is comprehensive and meticulous, suitable as review materials.
JS Basics Day2
operator
Assignment operator: operator that copies variables
Assign the value on the right side of the equal sign to the left side, requiring that the left side must be a container
=
-=
*=
/=
%=
unary operator
Example: positive and negative sign
self-increasing
symbol:
Function: Let the value of the variable be 1
Prefix auto-increment
Each time it is executed, the current variable value increases by 1
Its effect is equivalent to num = 1
Output the changed value
post-increment
Each time it is executed, the current variable value increases by 1
Its effect is equivalent to num = 1
Output the current value first and then calculate it
usage
There is no difference between the two when they are used independently.
Generally used independently during development
i post-increment is used relatively often, and is used alone
Decrease
symbol:--
Function: Let the value of the variable -1
comparison operator
>
<
>=
<=
==
===(strictly equal, judge whether equal during development, highly recommended)
!==
String comparison, compare the ASCII codes corresponding to characters
Compare from left to right (less used)
NaN is not equal to any number, including itself
Try not to compare decimals as there are accuracy issues
Logical Operators
&&
logical AND
and
The result is true only if both sides of the symbol are true.
A lie is a lie
||
logical or
or
If there is a true on both sides of the symbol, the result is true.
One truth is true
!
logical negation
Negate
T becomes F, F becomes T
True becomes false, false becomes true
operator precedence
Parentheses
()
unary operator
--!
arithmetic operators
First */% then -
Relational operators
> >= < <=
equality operator
== != === !==
Logical Operators
First && then ||
assignment operator
=
comma operator
,
Priority gradually decreases from top to bottom
statement
expressions and statements
expression
Code that can be evaluated, the JS engine will calculate a result
Because expressions can be evaluated, they can be written on the right side of the assignment statement.
statement
A statement is a piece of executable code
Statements do not necessarily have values, so statements such as alert() for and break cannot be used for assignment.
branch statement
Three major flow control statements of the program
sequential structure
branch structure
Loop structure
branch statement
if branch statement
Three ways to use
single branch
Single branch usage syntax
if (condition) {code to be executed if the condition is met}
When the condition in the brackets is true, enter the curly brackets to execute the code
If the result in parentheses is not of Boolean type, it will be implicitly converted to Boolean type.
If there is only one statement inside the braces, the braces can be omitted, but this is not recommended.
double branch
Double branch statement syntax
if (condition) {the code to be executed if the condition is met} else {the code to be executed if the condition is not met}
multiple branches
Multi-branch statement syntax
if (condition 1) {code 1} else if (condition 2) {code 2} else if (condition 3) {code 3} else {code 4}
First judge condition 1. If it is satisfied, execute code 1. If it is not satisfied, continue to judge downward.
If none of the conditions are met, execute else
There is no limit to the number of conditions and you can write unlimited numbers
ternary operator
Simpler way to write if double branch
symbol:? Use with:
Syntax: condition ? Code that meets the conditions for execution: Code that does not meet the conditions for execution
Generally used to get the value
switch statement
grammar
switch (data) {case value 1: code 1 break case value 2: code 2 break default: code n break}
Definition
Find the value of the case that is equal to the data in the brackets and execute the corresponding code inside
If there is no congruent ===, the code in default will be executed.
If the data is equal to value 2, execute code 2
Note:
The switch case statement is generally used for equality judgment and is not suitable for interval judgment.
Switch case generally needs to be used with the break keyword, otherwise it will cause case penetration.
loop statement
Breakpoint debugging
effect
It can help you better understand the code operation when studying, and you can find bugs faster when working.
Open the debugging interface in the browser
1. Press F12 to open the developer tools
2. Click on the sources (source code/source) column
3. Select the code file
while loop
Loop: Repeat some code
while: Repeat the execution of the code while satisfying...
Syntax: while (loop condition) {code to be executed repeatedly (loop body)}
Definition
It is very similar to the if statement. The condition in the parentheses must be true to execute the code in the loop body.
The code in the while braces will not jump out after it is executed. Instead, it will continue to return to the parentheses to determine whether the conditions are met. If so, it will continue to execute until the conditions in the parentheses are not met, then it will jump out.
Three elements
variable starting value
Termination condition (without termination condition, the loop will continue to execute, causing an infinite loop)
Variable change value (use auto-increment or auto-decrement)
loop exit
break: exit the loop
Exit the entire loop, generally used when the result has been obtained and is not needed in subsequent loops.
continue: End this loop and continue the next loop
Exit this loop, generally used to exclude or skip an option.