JS based tutorial --02 basic concepts

2. Basic concepts
2.1 identifier
identifier, said plainly, is a name.
Key: (1) The first character must be a letter, underscore (_) or dollar sign.
(2) Other characters can be letters, underscores, dollar signs or numbers.
(3) can not use keywords, reserved words, true, false and null.
2.2 Variable
declaration (1) Variable & variable assignment
syntax: var variable name = value;
(2) a plurality of keyword var variables may be defined at the same time, each variable with a comma "," separated.
2.3 Constants
Constant refers to an amount that can not be changed. That is, the value of the constant is defined from the beginning is fixed until the end of the program will not change.
In general, the constant names in all caps, others see that this value is very special, special purposes, such as: var DEBUG = 1;

2.4 数据类型
    数据类型,说白了,就是值的类型。
    数据类型可以分为两种,一种是“基本数据类型”,另外一种是“引用数据类型”。其中,基本

Only one data type value, and may contain a plurality of types of reference data values.
There are five basic types of data: number (Number), string (String), Boolean (Boolean), an undefined value (Undefined), and null (Null). The common reference data, there are two types: Array (Array), objects (Object).
(3) Boolean
Boolean only two types: true and false
Boolean value is maximum use is: Select conditional structure.
(4) an undefined value
variable var to declare all been used but not assigned, the value is undefined.
** var variable name = undefined; represents being the first not assign values to variables.
(5) null
var variable name = null; indicates that the system is no memory space is allocated to this variable.
2.5 operator
(1) Arithmetic Operators + / - /
/ ÷ /% / ++ / -
--------------------------- --- added: increment and decrement operators have two versions: a front type and a rear type
(2) assignment operator = / = + / - = / * = / ÷ = /% =
(. 3) comparison operators > / </ == /> = / <= /! = / === /! ==
! (4) Logical Operators / && / ||
(. 5) conditional operator var variable name = value determination condition is the condition of true:? A condition value to false;
(. 6) the comma operator comma operator and more used to declare multiple variables
2.6 flow control statements
(1) selection structure
①if statement: Select way: if (determination condition) ?????
way choice: if (determination condition) the else ··· ···
multi selection: ··· else if if (determination condition) ( Analyzing conditions) ????? the else ?????
②switch statement: switch (determination value) {
Case ranging from 1:
Chunk 1;
BREAK;
Case value 2:
Chunk 2;
BREAK;
......
Case value n:
Chunk n-;
BREAK;
default:
statement block. 1 + n-;
}
------------------------------------- supplementary: break statement to the end of the switch statement, if there is no break statement, the statement "corresponds branch" is executed, the branch will continue to be behind the execution of the switch.
(2) cyclic structure
①while statement: while (determination condition) ?????
②do the while-statement: do {···} while (determination condition);
Description: do-while statement first loop is unconditionally executed once, and then determines eligibility. If you qualify, it repeats the loop body; if you do not qualify, you exit the loop.
After the end of the do-while statement parentheses ▲ a semicolon (;), which must not be omitted semicolon.
③for statement: for (initialization expression; Analyzing conditions; post-cycle operation) ?????
④for-in statement: for (var variable name in the object) ???
Description: for-in statement is used to iterate through all of the properties of the object.
Here var operator is not essential, but in order to ensure the use of local variables.
The main difference ⑤break statement and continue statement is: break the cycle is completely over, and continue to end this cycle, and start the next cycle.
2.7 Function
(. 1) return statement
① can return a value obtained by return statement
②return;
----------- This usage is generally used to stop the function execution.
(2) parameter
arguments object array (the Array) similar:
①arguments [n-] to access each argument
②arguments.length arguments determine the number of

Guess you like

Origin www.cnblogs.com/zhangguishan/p/12468086.html