JS Advanced Programming (Third edition) study notes (first edition)

Source: Internet
Author: User

ECMA: European Association of Computer Manufacturers
ISO/IEC: International standardization and International Electrotechnical Commission


DOM Level (10*) Document Object model
1:dom core (Map-based XML document) and Dom HTML (based on the DOM core)
2: Support for mouse, event, range, traversal, and CSS stylesheet
DOM2: New Interface ... View, events (mouse, move), Style (CSS), traversal with scope (action on the document tree)
3: Load and save the document, validate the module, extend the core to the xml.0 specification
Other DOM
SVG Scalable Vector graph
MathML Mathematical Markup Language
Mghi Synchronous Multimedia Integrated language
IE5 dom1
Mozilla 0.6.0 supports DOM
Firefox3 fully supports dom1 dom2 dom3 (partial)

BOM (6*) Browser object model
Pop up a new window
Move, Bloom, close the browser window
Provide browser details Location object
Provide user display resolution screen object

Use the JS method in HTML
<script></script> use inside HTML
<script src= ' js.js ' ></script> external use
Properties: Async: Used to download this script, only valid for external JS files
CharSet: Character set (normally, set to Utf-8)
Defer deferred execution script, valid before IE7 version (for external JS files)
Language: Not in use
Type: script file content, JS on the server side, using the MIME:APPLICATION/X-JAVASCIPRT
SRC: External file path
Alert (obj) prints obj string contents
Console.log (obj) output obj string contents to the console
Now the Web application will put the JS file inside the body layer to use, the advantage is: When the JS code is downloaded, it will and the body
The contents of the content are displayed at the same time, if the JS file is stored in the head, it will be downloaded, parsed, and executed before it is rendered
Now body body content, this will appear in the middle of the delay time, will cause a part of the page blank.
The H5 specification executes the script in the order in which they appear.
IE4 to IE7 to defer this attribute is supported, after IE8, exactly according to the H5 rule to formulate
ie4,firefox3.5 SAFARI5 Chrome is the first to support defer properties
XHTML to be set to defer= ' defer '
Async (Asynchronous script) is similar to defer, but it does not guarantee the order in which the scripts are executed
XHTML to be set to async= ' async '


JS Basics
1: Case Sensitive
2: Cannot start with a number, the first character must begin with a letter or underscore or $, followed by a letter or underscore or a $ or number
, using the Hump case (first letter lowercase, each of the other words in the first letter capitalized)
3: Cannot use keywords, such as Functinon, class,if, etc.

Single-line Comment
/* * * Multi-line Comment


Object-based in JS
Strict mode
' Use strict ' support (Ie10+,firefor4+,safari5.1+,opera12+,chrome)
At the end of each statement, use a semicolon (;) to end;

Variable
var obj; This is a declaration, but there is no initialization value, and if you print the only declared variable of obj, the undefined is displayed (undefined
);
Obj=[]; means to pass the data on the right to the left obj variable, so that the obj variable generates a unique ID address in the memory address
Variable: It is a kind of data type used to save JS (such as shaping, array), and is dynamic when this variable obj changes
Its data type, the in-memory (unique ID) address is then changed

If you use Var to declare a variable in function, then the variable will be a local variable, and if function is finished, then
All (for example, local variables) in function will be GC (recycle mechanism), if Var is not used in function to declare variables
, this variable will be a global variable
VAR multi-line definition: var f1=1,f2=2,f3=[];
Note: In strict mode: You cannot use a variable such as eval or arguments
Data type:
Undefined null Boolean number string (Special data type: Object)
TypeOf: Detects what data type the given variable is (it is an operator, not a function), as follows
Basic syntax: typeof obj;
TypeOf will return the following cases
Undefined: Not defined
Boolean: Boolean value
String: Strings
Number: Value
Object: Objects or null
Function: Functions

Undefined: When using VAR declaration, but not initialized, then it is undefined

var a=1,b=2,c=[];
A,b,c=b,a+b,c Exchange
Judging type: typeof obj, obj instanceof objx (recommended)

Null Empty pointer object: (returns object objects) NULL is used when the variable that holds the object has not yet become a true variable, given by the programmer
, use NULL to see if the corresponding variable has saved a reference to an object
The value of the undefined that is derived from the null value.
The equality operator (true) between undefined and null is the main purpose: to convert its operands
Undefined when there is no need to display a variable, and there is no time to initialize obj, the computer gives

Boolean:true (not necessarily 1), false (not necessarily 0)
var t1=true;
var F1=false;
Use the Boolean (obj) function to cast obj to a Boolean value, and the returned result is true or false;

Number: Value
Integral type:
Decimal: Var intnum=55;
Octal: 070; (in strict mode, an error occurs if you use octal)
Hex: 0x25;

Floating point: (as determined by computer precision), with a maximum precision of 17 decimal places, but with precision problems when calculating arithmetic
0.1+0.2 equals 0.30000000000000004 in this way

var floatnum=1.23;

Number's minimum range: Number.min_value (5e-324)
Maximum range: Number.MAX_VALUE (1.7976931348623157e+308)
If not above (the maximum and minimum range) is automatically converted to a special +-infinity (infinity) value, it is a non-computed
Special data structure;
The Isfinite () function is used to determine whether this parameter is between the minimum and maximum values, or if true, otherwise flase

As follows
A=number.max_value+number.min_value
Alert
(Isfinite (a))

Number.negative_infinity Number.POSITIVE.INFINITY can also get the value of +-infinity;


Nan: Represents a value that would otherwise return a numeric operator that does not return data (no error), and what number in JS is nan except 0
Feature: Any number with Nan is calculated (including Nan) to return Nan
Nan is not equal to any data (including Nan itself)
The IsNaN () function, which can accept a parameter, is used to determine if it is not a value, and when IsNaN () accepts a value, it attempts to
Value is converted to data, and if the parameter is a non-numeric value, the return result is true, as follows
IsNaN (")
IsNaN () also applies to objects, and if the IsNaN () function is called, the object's valueof () object is called first, and then the He object is determined to return
The return value can be converted to a numeric value, and if not, then the ToString () method is called again to test the return value


numeric conversions
Number () for any data type
Rule: If it is a Boolean value, convert to 0 and 1
If it is a number, it is passed in and returned
If NULL, 0 is returned
If it is undefined, return Nan
If it is a string
If the string contains only numbers (including a positive plus or minus sign), it is converted to decimal, as
' 1 ' will become 1, ' 011 ' will become 11 (ignore 11 in front of 0)
If the string contains a valid floating-point format, the corresponding floating-point format is converted (the rule is similar to the value converted)
If the string contains a valid hexadecimal format, convert to a decimal integer of the same size
If the string is empty, convert to 0
If the string is not a character other than the above criteria, it will be Nan
If it is an object, call the object's valueof () method, and then follow the rules above, if it is Nan, and then call the object
ToString () method, and then use the method above to process it, as follows


parseint () Converts a string, handles integers, and if the first is a numeric character or minus sign, it will continue to parse the next character, straight
To a non-numeric character or minus sign, returns Nan if a non-numeric or non-negative sign is encountered
parseint () support octal, hex, decimal, etc.
parseint (' 0x ') return
NaN, if there is no value or no value after 0x
parseint () second parameter (Specify a binary)
The parsefloat () usage is the same as parseint (), but the difference is that it can be used for integer and floating-point, if the first decimal point is encountered
When the second decimal point is encountered again, as
22.35.4, will return 22.35

String: Strings are immutable, and if you want to change the string variable, you must first destroy the string variable and then re-
Defined
In string, use +: it is stitching
Convert to String: Str.tostring (), by default, does not need to use parameters in ToString (), the default Decimal method returns the number
A value string that can be output in decimal, binary, and other related binary systems;

You can use the string () conversion function If you do not know whether the value is null or undefined
String () Conversion rule
If the value has ToString (), call this method (no parameter) to return the corresponding result
If NULL, returns ' null '
If it is undefined, return ' undefined '

null and undefined no ToString () method


Object objects, which can be used to add properties and/or methods to an instance object, or to customize the object
var o=new Object ();

Object Each instance has the following properties and methods
Constructor: Save create current object function: constructor, is Object ()
hasOwnProperty (PropertyName): Used to check whether a given property exists in the current object instance (not in the instance prototype),
PropertyName must be specified in string mode
isPrototypeOf (object): Determines whether an incoming object is a prototype of an incoming object
propertyIsEnumerable (PropertyName): Determines whether a given property can be enumerated using for-in, PropertyName must
Must be specified in string mode

ToString () returns the object string representation
ValueOf () Returns an object string, numeric or Boolean representation, as in the ToString () method
toLocaleString (): Returns a string representation of the string that corresponds to the execution environment region
Operator
Unary operator
i++: First Use the current value, then add 1
++i: Calculate first, then use this new value

+ +,--rules can be used in numeric, string, Boolean, float, object, etc.
If it is a valid numeric string, converted to a numeric value and then added minus 1, the string variable becomes a numeric variable
If it is not a valid numeric string, set the variable to Nan, and the string variable becomes a numeric variable
When used for Boolean, convert to 0 or 1 and then add minus 1, the Boolean variable becomes a numeric variable
When floating-point values, perform a plus minus 1 operation
If it is an object, call the object's valueof () method, and then follow the rules above, if it is Nan, and then call the
Like the ToString () method, and then use the method above to process it again
var o={
Valueof:function ()
{


return-1;

}

};

Unary add only Left: (+,-, *,/), etc.
Obj=+obj, if +/-is placed in front of obj, does not have any effect on the +/-obj value

Bitwise operator (reshape) {Temporarily not discussed in this section}


Boolean operator
Not (non) and (with) or (or)

Not (!)
Rules
The following conditions return FALSE if the not condition is used
If the object/non-character/non-0 value
In addition to the above conditions are true

JS can use an odd number! Represents a not even number!

and (&&): true if expression 1 and expression 2 are true

The first one is the object, and the second condition is returned
One is NULL, then NULL is returned
One is Nan and the Nan is returned
One is undefined, then return undefined


or (| |)
True if one of the conditional expressions is true

If the first is an object, the first one is returned
If the first condition is false, the second one is returned
If 2 are objects, the first one is returned
If 2 are null/nan/undefined, return to null/nan/undefined;

Multiplication: *
Rules
If it is a numeric value, the normal calculation is performed, whether it is 2 positive or 2 negative, the result is positive, if one of them is signed
, the returned result is a negative number, and if multiplied and out of range, returns Infinity or-infinity
If one is Nan, the Nan is returned
Returns Nan if infinity is multiplied by 0
Returns +/infinity if Infinity is multiplied by a value other than 0
If infinity is multiplied, it returns infinity
If one of these is not a numeric value, then number () is called in the background and will be converted to a numeric value, then calculated according to the rules above

Division (/)
Its rules are similar to multiplication
If it is a numeric value, the normal calculation is performed, whether it is 2 positive or 2 negative, the result is positive, if one of them is signed
, the returned result is a negative number, and if multiplied and out of range, returns Infinity or-infinity
If one is Nan, the Nan is returned
Add a few different
0 divided by 0, return Nan
Non 0 except 0, return +-infinity
If Infinity is divided, it returns Nan;
If infinity is removed by any value other than 0, return +-infinity
If one of these is not a numeric value, then number () is called in the background and will be converted to a numeric value, then calculated according to the rules above

Modulus (%)
Its rules are similar to multiplication
If it is a numeric value, the general calculation is performed
If one is Nan, the Nan is returned
If the divisor is an infinity value and the divisor is a finite number, return Nan
If the divisor is a finite large and the divisor is 0, return Nan
If Infinity is divided, return nan
If the divisor is a finite number, and the divisor is an infinite number, the result is dividend
If the divisor is 0, the return is 0
If one of these is not a numeric value, then number () is called in the background and will be converted to a numeric value, then calculated according to the rules above

Plus (+)
When not a string
If the addition is not a string, then the general calculation
If calculated between +/-infinity, returns +/-infinity
If infinity and-infinty are evaluated, return Nan
If the calculation between +/-0, then is the general calculation
Except -0+-0 equals-0 outside

If it is a string (+), then stitching
If only one operator is a string, convert the other to a string and then stitch
If the operator is an object, numeric value, or Boolean, then the ToString () method that calls them gets the corresponding string value, and then
According to the above rules, for null and undefined call the string () function separately and get the strings ' null ' and ' undefined '


Subtraction (-)

Rules:
If all are numeric, perform general calculations
If one is Nan, return nan
Infinity and infinity calculate, return Nan
-infinity and-infinity calculate, return nan
Infinity and infinit-y calculate, return infinity
-infinity and Infinity calculate, return-infinity
If one is a string, a Boolean value, NULL, or undefined first calls the number () function from the background to a numeric value, and then according to the
The subtraction rule, if the conversion result is Nan, then the result is Nan;
When the valueof () method of the object is called, if the resulting result is Nan, then a nan is returned, and if no valueof () method is called, the
ToString () method, and then converts the string to a numeric value;


Relational operators
<,>,>=,<=,!=,==
Rules:
If the comparison is a numeric value, then a numeric comparison is performed
If it is a string comparison, then the encoding of the corresponding string is obtained
If one is a numeric value, the other is converted to a numeric value and then compared
If one is an object, then the valueof () method of the object is called first, then the above rule is used, if there is no valueof () party
method, if the object does not have a valueof () method, call the ToString () method and perform a comparison based on the results above

If one is a Boolean, then it is converted to a numeric value and then compared

If one compares with Nan, returns false forever
When a string is compared to a numeric value, it always returns false, because the string is converted to Nan.
Summary: When any operand is compared with Nan, it is always false;


Equality operators (= = and! =): First conversion and comparison, congruent and not congruent--only compare without conversion
Rules
If one is Boolean, convert it to numeric--false (0) and True (1) before comparing equality
If one is a numeric value and the other is a string, the string is first converted to a numeric value and then compared
If one is an object and the other is not, then call the object ValueOf () method and compare it with the rules above

If 2 operators are compared, use the following rules
Null is equal to undefined
Before you compare the equality. Do not convert null and undefined to any other value
If one is Nan, the returned result is false, and not equal returns True
A comparison between Nan, always false, that is Nan is not equal to Nan
Special values
True==2;false
Undefined==0;false
Null==0;false
' 5 ' ==5;true

Str.tolowercase () lowercase
Str.touppercase () Uppercase


Congruent (= = =) is not converted, only compared, if the result is false, because the corresponding data type is different
Conditional expressions
Ternary operator Exr0? EXR1:EXR2

Assignment operator: assigns the right value to the left variable
+=,-=,*=,/=
<<= left shift >>= right shift
>>>= Unsigned Right Shift
Multi-line statements
var a=1,b=2,c=2;
var num= (1,2,3,4,5); result num is 5 and will get the last value of num


Statement body
If statement
Grammar
if (expression 1) {

Statement Body 1
if (expression _0) {


}else{
Statement body
}
}else if (expression 2) {

Statement Body 1
}else{

Statement Body 3
}
If the IF condition expression is true, the body of the statement below the IF statement is executed, and the else if else related statement is no longer executed
If the IF condition expression is flase, perform the else if (if multiple, if it is true, execution) else is not executing
If none of the above conditions are met, the Else statement is executed

Do-while test the Loop statement after the exit condition is tested only after the code is executed in the loop body (at least one code request is executed)
Grammar
do{

Statement body
}
while (expression);

While statement (normally, if it is not in order, use it)
Grammar
while (expression) {

Statement body
}


For loop
Grammar:
for (expression 1, expression 2, expression 3) {

Statement body

The For loop is the same as the while loop.
In a For loop, in a variable initialization expression, you can generate this variable externally without using the VAR keyword, because the external variable
can be accessed in the For loop
var Count=0,i=1;
for (i;count;i++) {

}
Dead loop
for (;;) {

}
while (true) {


}

For-in Iteration Statement Body (similar to Python: enumeration)
Grammar
For (iteration alias in expression) {

Statement body

}
Before for-in is used, the value of the object is detected as null or undefined


}

(1*) Label statement
Grammar
Label: expression, commonly used for loops together
Role: is to add tags in the code to facilitate future use

Break (jump out of the loop, not in execution) and continue (jump out of the loop and then continue from the top of the loop) with the label statement
Use
And you can add a variable after break/continue, as follows
Label:for () {
Break label

}

With statement
Grammar:
With (expression) {

Statement body
}
Role: Set the scope of the code to a specific object, primarily to simplify writing the same object multiple times
Disadvantage, using with can degrade performance, and in development, it is not recommended to use

(10*) switch statement
Grammar
switch (expression) {
Case v1: Expression
Break
....
Case VN: Expression n
Break
Default
An expression
}
Its syntax is similar to the IF statement
Note: When you omit break in a case, you continue to execute the code in the next scenario statement
Default is used to not match all previous case statements in an expression
If break is omitted in the case, it is recommended that you use a comment to illustrate the situation
The V1 here can represent more than just numeric values, but also other data types, such as objects.


Function
Grammar
function funcname (formal parameter) {
function body

}funcname (actual argument)

Formal parameters are also local variables
function FuncName (parameter < pass value >) {

var funcname; local Variables
}

FuncName (argument value) argument is a global variable


In JS, function in parentheses inside the parameters, no matter how much or do not give, JS will never error, will not care about the parameters passed in is
What type, because in the JS internal mechanism uses an array to represent, even if this parameter is 0 or more, JS also has nothing wrong
Tips
Length of array: Array.Length

Arguments.lenght can get the number of arguments passed to a function in a function name
Arguments[int] It can also be used with parameters

Arguments its value is always synchronized with the value of the corresponding named parameter

JS Advanced Programming (Third edition) study notes (first edition)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.