Grammar:
1. Case-sensitive!!
2. Identifier: variable, function name, property name, parameter.
1. The first character must be a letter, _, or $
2. Other characters can be letters, _,&, or numbers
3. Notes:
1. Single-line Comment://
2. Multiline Comment:/* */
4. Strict mode: Specify "Use strict" at the beginning of the function body
function do () { "user strict"; function Body }
5. Keywords and reserved words: cannot be used for identifiers
Keywords and reserved word collation http://www.qeefee.com/js/javascript-keywords-reservedwords
6. Variables
The variable used for the definition of the VAR operator will be the local variable that defines the variable, and the variable will be destroyed when the function exits, using var to define a variable.
The life of a variable is divided into an explicit declaration (Var i=0, as a local variable) and an implicit declaration (i=0, as a global variable).
7. Data type
Base data type: null,boolean,string,number,undefined
Complex data type: Object
8.typeof operator
The data type used to determine the variable, literal
The return value is "undefined", "boolean", "Number", "string", "Object", "function"
9.Undefined type
The value is only undefined, and when you declare a variable with var without initializing it, the value is undefined, and for a VAR mess it defaults to Var mess=undefined
For undeclared and uninitialized variables, the return value of typeof is undefined
10.Null type
The value is only null, and for Var car=null, its typeof return value is Object
11.Boolean type
A value of true false
For any data type, you can use the Boolean () function to cast to a Boolean type, and for a return value of TRUE or FALSE, the main view is the conversion rule
Data type |
Convert to True |
Convert to False |
Boolean |
True |
False |
String |
Non-empty string |
"" (empty string) |
Number |
Any non-0 digit |
0 and Nan (non-numeric) |
Object |
Any object |
Null |
Undefined |
N/a no application (neither applicable)
|
unfined |
var message= "Hello World"; if (message) { alert ("Hello");}
12.Number type
Defines the octal number Var num=070 is the octal 56 that is, in the 8 binary literal, the first bit must be 0 16 binary in the top two bits of 0x
Isfinite () Determines whether a number is poor (is not between the maximum number.max_value and the minimum value. Number.min_value).
Nan--not a number (non-numeric) any value divided by a non-numeric value will return Nan,nan with no values to wait, including his own
IsNaN () Determines whether the parameter is a non-numeric value, IsNaN () after receiving the parameter, the first attempt to convert it to a numeric value (this process executes only 1 times), call the number () function, and then judge, so the return value of IsNaN ("10") is still false, even if "10" is a string, and IsNaN (true) is also false, because false can be converted to the number 1.
Numeric Conversions: Transformation function number (), String conversion function parseint (), parsefloat ()
Number () function conversion rule
Boolean |
True is 1,false to 0 |
Null |
0 |
Undefined |
NaN |
Number |
Return as is |
String |
1. String only number, return the corresponding 10 binary, such as "11" return 11, "011" return 11 (including +-number) 2. String content is floating-point number, return floating-point number 3. String content contains 16 binary formats, such as "0xf", returns 10 binary of the same size 4. String is empty, return 0 5. String contains other formats, return Nan |
Object |
Call valueof (), return the corresponding value according to the preceding rule, and if the conversion result is Nan, call the ToString () and return the value according to the above rule |
The return value of Praseint ()/prasefloat () to an empty string is Nan, and they extract only the valid digits and the decimal point
You can set a second optional parameter for Praseint (), specifying both the binary when converting
13.String type
Concatenation of strings by using the + operator
ToString () is converted to a string, and null and undenined do not have this method, and the optional argument is the binary number
String () Transformation functions, rules, for types with the ToString () method, should take precedence over ToString (), or null if the value is null, and return "undefined" if the value is undefined;
14.Object type
An object is a set of functions that is a collection of data, which should be created by the new operator followed by the name of the object type to be created, and create an instance of type object and create a custom object for adding properties and methods to it. All methods and types owned by the Object type also exist in the instance. Var obj=new Object ();
Constructor: constructor for preserving the function of the created object, the constructor in the example above is object ();
hasOwnProperty (PropertyName): Used to check whether a given property is in an instance of the current object. Usage: obj.hasownproperty ("name");
propertyIsEnumerable (PropertyName): Used to check if a for-in loop can be used for a given generic type
isPrototypeOf (object): Used to check whether an incoming object is a prototype of the current object.
toLocaleString (): Returns the string representation of the object that corresponds to the region where the execution environment is executed.
ToString (): Returns the string representation of the object.
valueof (): Returns the string of an object, Boolean,number, usually the same as the return value of the ToString () method.
15. Operator: For ECMAScript, operators can be applied to many data types, such as Boolean,number,string,object, when applied to object, the corresponding operator usually calls the object's valueof () or ToString ( ) in order to obtain a value that can be manipulated. •
1. Arithmetic operators
2. Bitwise operators
For the most basic level, the value is manipulated both by the bit in memory to represent the numeric value (all the values in ECMAScript are stored in the IEEE-754 64-bit format, but the bitwise operators do not manipulate the 64-bit values directly, but instead first convert 64 bits to 32-bit integers, and after performing the operation, Convert to 64-bit) in addition, when nan,infinity applies bit operations, both values are treated as 0, and the bitwise operator automatically uses number () to transform when manipulating other data types.
For signed integers, the first 31 of the 32-bit is the value, the last one represents the sign bit (0 is +,1), the positive number is stored in pure 2, and each of the 31 bits is the power of 2, bits 0 represents 20, and so on. Negative numbers are stored in 2 complement (complement algorithm: 2 binary representation of the absolute value of the negative number first, then the inverse code, the last bit 0 plus 1)
Bitwise non (not) with ~, the result is a numeric inverse code var a=25, var b=~a;alert (b)//b==-26 can be seen as the essence is the negative value of the operand minus 1.
The bitwise AND (and) are represented by &, and the result of the operation is 2 binary.
A bitwise OR (or) representation of the result of a 2 binary or operation
Bitwise XOR (XOR) is expressed in ^, the result is based on the truth table, 1 0 is 1, 0 1 is 1, the other is 0
Shift left, with <<, move a few, with a few 0 fills (the fill appears in the lowest bit), does not affect the sign bit var a =2;var b=a<<5; alert (b);//b==64
Signed right shift, with >>, move a few, delete a few lows, and then the symbol bit to the right, the value of the left side of the value is filled with the values of the symbol bit. Do not affect symbol bit
Unsigned right shift, with >>>, 32 is moved to the right of fixed number, so the positive numbers, and >> results are the same, but for negative numbers, the unsigned right shift will be negative binary as a positive binary, so it is filled with 0 high
3. Relational operators
4. Equality operators
5. Pre-increment (decrement) and post-increment (decrement) differences in unary operators (which can only manipulate one worth operator): The value of a variable is executed before the statement is evaluated. Post: The value of the variable is executed only after the statement that contains it is executed
var age=21; var age=21;
var anotherage=++age +2; var anotherage=age++ +2;
Alert (age)--22; Alert (age)--22
Alert (anotherage)--Alertt (Anotherage)--23
The increment-decrement operation also applies to other data types, whose transformation rules are the same as number (), with the addition of increments and decrement operations
Unary plus (minus) operator Var a=1; a= +a; a==1 var a=1;a=-a;//a==-1 can also manipulate other data types with the same transformation rules as number ().
6. Boolean operators
Undefined values cannot be used in logical operations
Logical NON (! ), automatically use the Boolean () transform function, and then manipulate
Logic or (| | )
Logic and (&&)
7. Multiplicative operator (*)
When the * result is greater than the representation range of the ECMAScript value, it is represented by infinity.
Nan*num=nan
Infinity*0=nan
Infinity/infinity=nan
0/0=nan
Num (not 0 finite)/0=infinity sign bit depends on the positive or negative number of num
8. Additive operators
Note that when you add a string, the value is converted to a string
9. Congruent and non-congruent
Not congruent will call the transformation function by itself
10. Conditional operators
Variable =boolean_expersion? True_value:false_value;
16. Statements
The common basic is the flow control statement, no longer repeat
It is important to note that in ECMAScript, because there is no block-level scope, the variables defined within the loop can also be accessed externally to the
When for (;;), which is an infinite loop
For-in: An iterative statement used to enumerate the properties of an object, if the variable value of the iteration object is null or undefined, the loop body is not executed
for (Var propname in Window) {
document.write (propname);}
Label statement: Add tags to your code for future use of label:statement
Strat:for (var i=0;i<count;i++) {alert (i);}
Label generally with break/continue, break: Jump out of the current loop, execute the loop behind the statement, if nested, jump out of the outer loop. Continue: Jump out of the current loop, go back to the top of the loop and continue the loop, if nested, perform the outer loop.
17. Functions: Function ()
Methods for function calls: 1. Calling directly from the functions name
2. Define a variable to invoke (this method generally applies to functions that have return values)
The ECMAScript function does not have to specify whether to return a value, the code behind Renturn is never executed, Renturn can also take no return value, meaning that the function needs to terminate prematurely and does not require a return value, whose actual result is to return undefined
Parameter: The parameter is stored as an array in the JS interpreter, meaning that even if there is no parameter defined when defining the function, arguments can be added to the call, and the parameter array can be accessed using the arguments object in the body of the function.
<HTML><Head> <MetaCharSet= "UTF-8"> <title>Document</title></Head><Body> <Script> functionA () {alert (arguments[0]); Alert (arguments[0]+arguments[1]); alert (arguments.length); } A ("Hello"," World");</Script></Body></HTML>
ECMAScript parameter is not overloaded
Introduction to JavaScript 2--Basic concepts