1.js Introduction
A) JS is a web scripting language that allows browsers to interact with Web pages.
JS is an object-based and event-driven, security-capable scripting language, which is the language of the client's browser that can interact with the response handler without requiring the server's processing and response.
JS can also interact with the server response, while the server language (ASP, PHP, JSP) need to upload the command server, the server processing after the return processing results.
JS can be embedded in the HTML file, do not need to go through the Web server to respond to user action, so that the Web page and the user very good interaction, the use of client computer resources to properly reduce server-side pressure, and reduce the user's waiting time.
b) Features
Simple, requires only a browser to execute
Explain execution, do not compile in advance, execute line by row, do not need strict variable declaration
Object-based, with a large number of ready-made objects, just call
c) Role
Validation of client forms legitimacy
Web page Special Effects production
Invocation of the Browser object
Triggering of browser events
d) After HTML appears <script> tags, the page pauses the interpretation and execution of the download and render wait script, whether the current script is inline or out-of-chain.
Composition of 2.js (* * *)
ECMAScript: Grammar Standards
DOM: Manipulating elements on a Web page
BOM: Part of the function of the operating browser
3.js syntax specification, a line of code must be completed after the end;
Program execution from top to bottom, error stop encountered
-Inline notation
<script type= "Text/javascript" >
JS Code
</script>
? outer-connected notation
<script type= "Text/javascript" src= "1.js" >
JS code can no longer be written in this tag
</script>
4.js Output Information
A) Console.log () Information output to the console for JS debugging
b) prompt () Popup dialog box for receiving user input information
c) Confirm () Page Popup dialog box, with if judgment
d) document.write () on the page output information, but also output the label
5. Variables
a) variable declaration var variable name;
Variable Assignment variable name = ' Variable value '
Define and assign Var a=1;
6. Data type
A
Number numeric type
Strings string
BOOL Type Boolean
Undefined variable not initialized, no value assigned to variable
Null variable unreferenced value is null object
b
Object objects
Array arrays
C
typeof () to determine the data type
d) Comparison operators
< > <= >= = = =!
e) Arithmetic operators
+ number + Number = Numeric number + string = string
-numeric-numeric/numeric string = Numeric number-non-numeric string =nan (not a number means not a digit)
/numeric/numeric/numeric string = numeric numeric/non-numeric string =nan (numeric type) digital/0=infinity (infinite) (numeric type)
% take remainder
F
1.date () object processing date and time
2.Math objects
A
Math.ceil (n1) Ceiling function rounding up
Integer, after rounding is the number itself
Decimal, rounding up the logarithm.
b
Math.floor (n1) floor function
Integer, after rounding is the number itself
Decimal, rounding down the logarithm
C
Math.max (N1,N2) take the maximum value in two numbers
Math.min (N1,N2) Minimum value
Math.pow (N1,N2) N1 N2 the second party
Math.Round (N1) rounding
Math.random () returns the random number between 0-1
3. Data type Conversion
A) numeric type to string
String (N1)
N1.tostring ()
b) string to number
Number (N1)
parseint (N1)
Parsefloat (N1)
c) Turn Boolean type
Boolean (N1)
D
&& | | Or not!
E
"=" Assignment operator
the "= =" only determines whether the content is the same and does not determine the data type.
"= = =" Not only judge the content, but also determine whether the data type is the same.
! = Determines whether the content is not the same and does not determine the data type.
! = = Not all equals not only to determine whether the content is not the same, but also to determine whether the data type is not the same.
f) Variable Collective declaration
4.
a) If...else Condition Judgment
IF (conditional expression) {
If the conditional expression evaluates to True, the code is executed. If the conditional expression result is false, the code below executes.
}else{
If the conditional expression result is false, the code is executed.
}
b) If Else nesting
IF (conditional expression) {
If the conditional expression evaluates to True, the code is executed. The code below does not execute. If False, the code below is executed.
}else If (conditional expression) {
If the conditional expression evaluates to True, the code is executed. The code below does not execute. If False, the code below is executed.
}else if (conditional expression) {Executes the code if the condition expression evaluates to True. The code below does not execute. If False, the code below is executed.
}else{
If the upper condition expression evaluates to False, the code is executed.
}
c) three-dimensional expression
An expression? result 1: Result 2;
If the expression evaluates to true, execution Results 1, and if the expression evaluates to False, the result 2 is executed.
Can be understood as another way of writing if else.
5. Code debugging
F12
1.switch statements
The data type of the variable behind the switch and the value behind the case must be consistent
b) switch statement can be a collective judgment of variables
2. Self-increment self-reduction
i++ i--
3. Cycle
A) while loop
while (conditional expression) {
The loop executes as long as the conditional expression evaluates to True, and the loop terminates when the conditional expression evaluates to False
}
The while loop statement needs to define variables in the loop body now
b) Do While
do{
Loop body Code; First execute the Loop body code once. If the expression at the back of the while evaluates to true, the loop experiences a loop. If the result is false, the loop terminates.
}while (conditional expression)
Do While loops more than one time loop
c) For Loop
for (define variable; conditional expression; self-increment) {
Loop Body Code
}
Execution order:
Define variables First
If the conditional expression evaluates to True, the code in the For loop is executed, and if False, the loop body code terminates execution.
The variable and conditional expressions are executed once, and then the self-increment is performed.
D) in the loop, the program immediately ends the current loop as long as the code encounters a break
E
The continue statement refers to jumping out of the loop, where the code behind the statement is no longer executed and the entire loop body continues to loop.
4. Arrays
A) Create
b) Assign value
c) Initialize traversal
d) Array name. Length Get array lengths (number of elements)
e) Array Merge concat ()
f) The Join method returns an array of strings
5. Functions (Methods)
a) definition
b) Call
Summary of JS Basic grammar (i)