Read the order
This is the first article
The article directories
- The JavaScript function
- The composition of JavaScript
- JavaScript input and output statements
- Variable summary
- The data type
- IsNaN (judge non-numeric)
- Length (determine the length of the string)
- String splicing
- Typeof (Test variable types)
- Data type conversion
- Convert to string
- Conversion to Alphanumeric (emphasis)
- The operator
- Short circuit operation (logical interrupt)
- Process control branch
-
- Process control
- Sequential structure
- Branching structure (selection structure)
- Loop structure
-
- Ternary expression
-
- Branch flow controls switch statements
- 5.1 Syntax Structure
- 5.2 Edge removal of switch statements and if else if statements
The JavaScript function
- Form dynamic validation (password strength recognition)js is generated for purposes
- Web page special effects
- Server-side development (Node.js)
- Desktop applications
- app
- Control hardware Internet of things
- The game development
The composition of JavaScript
- ECMAScript(JavaScript)
- DOM(Page Document Object Model)
- BOM(Tourist Object Model)
JavaScript input and output statements
methods | instructions | attribution |
---|---|---|
Alert (MSG) | The warning box pops up on the browser | browser |
console.log | The viewer console prints out information | browser |
Prompt (info) | A dialog box is displayed for users to enter information | browser |
Declare multiple variables separated by commas
var a = 1,
b = 2,
c = 3 ;
Copy the code
Variable summary
-
Why you need variables
- You need to save the data
-
What is the variable
- A container for storing data
-
What is the nature of a variable
- A variable is a block of memory used to store data
-
How are variables used
- Declare first, then assign
- The essence of declaring a variable is to find space in memory
-
What is initialization of a variable
- Declaration and assignment are initializations
-
The conventions for naming variables are those
- See of knowledge meaning
-
Swap the values of two variables
- Use temporary variables
The data type
JavaScript is a dynamic language that determines data types based on the value to the right of =
The same variable can be of different types
Add 0 to octal and 0x to hexadecimal in JS
IsNaN (judge non-numeric)
isNaN() TURE OR FALSE
Length (determine the length of the string)
str.length
String splicing
String + any type = add new string values after concatenation, concatenate characters
Formula for connecting variables to strings: quote, quote, plus, plus
Typeof (Test variable types)
Consel.log (typeor XXX);Copy the code
Data type conversion
Convert to string
- ToString () xxx.toString ()
- String () cast String (XXX)
- Plus concatenation string
The third method is usually used, and this method is called implicit conversion
Conversion to Alphanumeric (emphasis)
- ParseInt (string) function
- ParseFloat (string) function
- Number (cast)
- Js implicit conversion, using arithmetic operation conversion, ’12’ -0
The operator
Postincrement returns the original value first, then +1
== converts a string to an integer
= = = all equal to zero
Short circuit operation (logical interrupt)
When there are multiple expressions, the value of the expression on the left determines the result, and the value of the expression on the right is not evaluated
Process control branch
1. Process control
Simply put, you control the order in which your code is executed
Sequential structure
Branching structure (selection structure)
According to different conditions, execute different code, get different results.
Loop structure
4. Ternary expressions
Ternary expressions can also make some simple conditional choices. A formula consisting of ternary operators is called a ternary expression
Grammatical structure:
Conditional expression? Expression 1: expression 2
Implement ideas
If the conditional expression is true, the value of expression 1 is returned; if it is false, the value of expression 2 is returned
5. Branch flow control switch statement
5.1 Syntax Structure
Switch statements are also multi-branch statements that execute different code based on different conditions.
Switch is used when you want to set a set of options for a variable with a specific value
Switch (expression){case value1: execute statement 1; break; Case value2: execute statement 2; break; . Default: Execute the last statement. }Copy the code
Implement ideas
The essence is matching
Matters needing attention:
- Expressions are often written as variables
- The value of num is congruent with case when matched
- If there is no break in the current case, the exit is not performed, and the next break is executed
5.2 Edge removal of switch statements and if else if statements
- In general, they can be converted to each other
- switch… Case statements typically handle cases where case is determined by comparison, if… Else is more flexible and is often used for ranges (greater than or equal to a range)
- The switch directly jumps into the execution of the statement, which is efficient
- When there are fewer branches, if… Else statements execute more efficiently than switch statements
- With more branches, the switch performs more efficiently and has a clearer structure