I taught CSS and JavaScript a few days before learning pcti in phpchina.
Javascript identifier
An identifier is a symbol defined in Javascript, such as the variable name, function name, and array name.
An identifier can be composed of uppercase/lowercase letters, numbers, underscores, and dollar symbols in any order. An identifier cannot start with a number or use reserved keywords in JavaScript.
Performanceipt is case-sensitive. Each function ends with a semicolon. Each word is separated by a separator such as a space, tab, line break, braces, and parentheses.
~~~~~~~~ Although the above part is a bit nagging, it must be strictly observed. Therefore, you need to write ~~~~~~~~~~~~~~~~
Types and constants of basic data
Integer constant
The hexadecimal format starts with 0x or 0x, for example, 0x8a.
The octal value must start with 0, for example, 0123.
The first digit in decimal format cannot be 0 (excluding digits 0), for example, 123.
Real Constants
12.32, 192.98, 5e7, and 4e5.
. 0001, 0.0001, 1e-4, 1.0e-4
I won't say much about the above part. I don't need to study it, but I must have a concept.
Boolean
True and false. True true True False false
Null constant null indicates that the keyword contained in the variable is invalid. In other words, the variable does not save valid numbers, strings, Boolean, arrays, or objects. You can assign a null value to a variable to clear the content of the variable.
The undefined constant undefined is undefined. It is a member of the Global Object and can be used after the Script Engine initialization. If a variable has been declared but has not been initialized, the value of this variable is undefined.
String constants
"This is JavaScript PPT", 'abc', "a", and "".
Special characters in a string, which must be expressed by a backslash (\) followed by a common character. For example: \ r, \ n, \ t, \ B ,\',\",\\.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Variable
To declare a variable in Javascript, you must use the VaR keyword to declare the variable and assign a value to it when declaring the variable.
For example, VAR name = "zhansan ";
Assign a value to another type of data.
Such as VAR name = 123;
Use directly without prior declaration
Example: x = 1234;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Operator
Operators include Arithmetic Operators, value assignment operators, comparison operators, logical operators, and bitwise operators.
I will not write more about others. I will only write the logical operators and bitwise operators in JavaScript.
Logical operators
& Logical and, true is returned when both the left and right operands are true. Otherwise, false is returned.
| Logic or. If both sides of the operand are false, false is returned. Otherwise, true is returned.
! = Non-logical. If the operand is true, false is returned. Otherwise, true is returned.
Bitwise operators
Bitwise operations are used to calculate every binary bit in the operand, including bitwise logical operators and displacement operators.
& The result of the operation is 1 only when the two involved operators are 1; otherwise, the result is 0.
| The result of the operation is 0 only when both of the involved values are 0. Otherwise, the value is 1.
^ The result of the operation is 1 only when the two involved operations are different; otherwise, the result is 0.
> Shifts the binary data of the left operand in the memory right to the specified number of digits of the right operand, and the left to the empty part to add the original highest binary value of the left operand.
<Shifts the binary data of the left operand in the memory left to the number of digits specified by the right operator, and adds 0 to the left operand.
>>> Shifts the binary data in the memory on the left to the right to the number of digits specified by the right operation, and fills in the left blank part with 0.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Program Process Control
Sequence Structure, if condition selection statement, switch selection statement, while loop statement, do while statement, for loop statement, and break and continue statement.
First, the IF condition selection statement
If (Condition Statement) is determined by if
{
Execute statement Block 1. If it is true (true), execute Statement 1.
}
Else
{
Execute Statement 2. If it is false, execute Statement 2.
}
Short for if
{
More: If (x = NULL) or if (typeof (x) = "undefined") can be abbreviated as if (! X ).
More: Variable = Boolean expression? Statement 1: Statement 2;
For example, y = x> 0? X:-X;
}
If statements can be nested.
Switch statement
The following is an example of a switch statement.
VaR x = 2; first set a variable X = 2
Switch (X) and then switch to determine
{
Case 1: Set the case value to the number of switches
Alert ("Monday"); the alert statement block executes the alert value when the switch selects the value.
Break; break jump out: jump out of the program after execution
Case 2:
Alert ("Tuesday"); alert prompts information for the browser
Break;
Case 3:
Alert ("wendnesday ");
Break;
Default: default (default): Run this section if none of the preceding conditions are met.Code
Alert ("sorry, I don't know ");
}
The execution result of the preceding statement is "Tuesday"
Switch can also be used in this way
VaR x = 2;
Switch (X)
{
Case 1:
Case 2:
Case 3:
Case 4:
Case 5:
Alert ("working day ");
Break;
Default:
Alert ("Off day ");
}
Try it by yourself.
While loop statement
This is a simple example of a while loop statement.
VaR x = 1; first, we need to set a variable X = 1.
While (x <3) then use while to determine if X is less than 3
{
Alert ("x =" + x); If you determine that X is less than three, execute this section. Alert displays the information in the browser ("x =") as is (+ x) returns the value of X after the output.
X ++; then x ++ indicates that if X is less than 3, it will accumulate.
}
The difference between the do switch loop statement and the switch statement is that the switch is executed after judgment, and the do switch statement is executed before judgment.
For Loop statement
The following is an example of a For Loop:
VaR output = ""; first set a variable but not assign a value
For (VAR x = 1; x <10; X ++) for determining whether the variable X = 1 is less than 10. If it is less than 10, then x ++
{
Output = output + "x =" + X; variable output equals utput plus Original output "x =" + x value
}
Alert (output); the output value of the variable is displayed in the browser.
Break and continue statements
Break is used to jump out of the current program
Continue is the current iteration of the Stop loop and starts a new iteration.