JavaScript-- gallop script execution's Web page (1)

First, with regard to JavaScript

JavaScript return to the birth of the original intention is to reduce the burden on the site form validation part of the back-end server and the user both sides suffer, so that some basic data test can be completed in the front page, instead of wasting back-end server resources, but also reduce the back-end validation the page jump action brought by the network burden.

JavaScript original name LiveScript , then stir in the media in order to catch java ride (rub heat), changed its name to the official release on the eve of JavaScript . Since the browser vendors for different implementations script control, when the JavaScript has a different version, but in the European Computer Manufacturers Association ECMA defines the ECMAScript standard, the various browser vendors committed to ECMAScript as each implement JavaScript -based.

JavaScript consists of three parts: ECMAScript ( JavaScript syntax standard), the DOM (Document Object Model, can be understood as JS operation HTML ), BOM (browser object model, can be understood as JS operation browser).

All major browsers are equipped with JS interpreter for interpreting execute JavaScript scripts. Google 's v8 engine JavaScript interpreter and later developed into a nodejs , nodejs allows JavaScript code that not only can run in the browser, can also run on the server side, so JavaScript has the ability to programming languages. JavaScript running in the browser can do animation, form validation, Ajax data exchange, etc., do operate at the server side has JS conversion, code compiler, a database operation, operational flow, network programming, The IOT of (IOT) and many more.

 

Two, JavaScript variables

JavaScript type Data type depends on the value of the variable, is a weakly typed language (depending on the data type of the variable part of the variable declaration strongly typed language), and may change with the change of the value of the type of the variable type.

JavaScript basic data types are: Number (hexadecimal number of various types), String (string type), Boolean (boolean), null (empty object type) and undefined (untyped). NaN , Infinity represent non-numeric and infinite value.

" Typeof variable" variable type expression can be represented by a string name; " isNaN ( variable ) " may determine whether the expression is not a variable Number (digital type); " isFinite ( variable ) if" expression can be determined that there is a variable number of poor ( JavaScript believe 0 occurring in the operation except when the infinitesimally small number, so the result of an infinite number of possible).

Although the order of execution is JavaScript language features, but the JavaScript will first be made before the implementation of a variable text of a statement, so that only the variable declaration below can be used in the above, only the variable type is undefined , but if you use full-text none declared the variable will be given.

JavaScript reference data types: array type, function types and object types.

Value of the basic data types is stored in the stack area; reference data type stored in the reference address stack area, which is saved in the stack area.

 

Three, the JavaScript operator and type conversion

1. The arithmetic operators (omitted)

 

2. unary

Save increment operator, such as:

++ represents the increment, - on behalf of decrement. The first number represents the increment, decrement and then participate in other operations when the number before they are placed; represents the number of other operators to participate when they are placed on the number, then increment, decrement, such as:

There are a = 3;

var b = 1;

var result = ++a+b++;

++a; //a = 4;

a+b //result = 5;

b++ //b = 2;

 

+ Representatives added, also represents a positive number, but also other data types can be converted to a digital type, such as:

+true //1

+'11' //11

 

- Representative reduced, also represent negative, but also other data types can be converted into a digital type, such as

-(-true) //1

-(-'11') //11

 

3. assignment and comparison operators

" = " Is the assignment operator, the right-hand side is assigned the value of the left side of the equal sign. " == " indicates an equal value on both sides, " === " means both sides of the data type and values are equal, " ! == " indicates the type of data varies, but on both sides of equal value, commonly used in the determination.

 

4. The logical operators (operator short circuit portion)

( 1 ) " && " indicates a logical and, when the first time the expression is false, no second expression, the whole expression is determined by the first expression, then returns the first a calculation result of the expression, i.e., if the first operand is false, null, undefined, NaN, 0 , or "" (a Boolean type indicates to false ), the results are returned value; other if the first number, a second number of results are returned. Such as:

where s1 = 8;

var s2 = "briup";

var s3 = "";

var result = s3 && s2; // "" empty string

var result2 = s1 && s2; //briup

 

(2 ) "||" represents a logical or, when the first expression is true, the entire expression result is true, the second expression is not evaluated, then returns the first expression, i.e. if the first operand is not false, null, undefined, NaN, 0 or "" , the results are returned value; if the first operand is null, NaN, undefined, false, 0 or "" , the result will be returned second operand.

 

( 3 ") ! " Represents a non-, the operator applied to any type of return value of a Boolean value, it will first convert any type of value is Boolean , then negated, such as:

! a // equivalent to ! Boolean (A) , A non- 0 of the number returns false

!0 //true

!"" //true

! In true //

!false //true

Once every two logical negation , can be converted to any data type Boolean type

!! a // equivalent to Boolean (A) , A non- 0 of the number returns true

!!"" //false

 

The ternary operator ( " ? And" " : combinations")

variable = boolean_expression ? true_value : false_value;

If boolean_expression is to true , then the true_value assigned to the variable , otherwise it will false_value assigned to the variable .

 

6. Use " + " operation in situations (in m + n Example)

When m, n is not String, Object type, the first m, n convert Number Type, and then calculated as:

true + false; //1number(true)+number(false);

true + 1; //2number(true) + 1

null + undefined; //NaNnumber(undefined) + number(NaN)

 

When m, n there is a String , the other operand is a Whether other types of objects, to be converted to a String , and then to the string concatenation operator, such as:

"1" + true; // 1true

"1" + undefined; // 1undefined

"1" + 1; // 11

 

When m, n has an object , if the object is both rewritable toString, a rewrite valueOf method will first call valueOf method of acquiring a return value, the return value and another operand operation. If the object does not override valueOf method calls toString method Returns a value (a string), and the return value and further calculates an operand (string concatenation), such as:

There he = {

name:"briup",

valueOf:function()

return "1";

}

}

a + 1; // 2 , (1 + 1)

 

7. Type Conversion Summary

(1) Other data types into a number primarily by Number () function , the parseInt () function, parseFloat () function of these three forms.

By Number () function transformation, for example:

If the conversion value is null, undefined, boolean, number

Number(true); //1

Number(false); //0

Number(null); //0

Number(undefined); //NaN

Number (10); // 10 (if the digital value is output)

If the conversion value is the string

Number The ( "123"); // 123 ; if it contains only a value, the value is converted to the corresponding

Number The ( "234.1"); //234.1 ; resolve to a corresponding decimal

Number The ( "+ 12.1"); //12.1 ; the first sign bit, the rest is a numerical value, the value is converted to the corresponding

Number ( "1 + 2.3") ; // sign bits occur at other locations, to resolve NaN

Number The ( "0xA"); // 10 ; If the value contains only hexadecimal format, converted to the corresponding decimal

Number ( "010"); // [Note! ] Will not be parsed as octal, the result is 10

Number ( ""); // empty string is converted into 0

Number ( "123ac"); // contains other characters , resolved to NaN

Number(" 12"); //12

 

By the parseInt () function transformation, for example:

If the conversion value is null, undefined, boolean , converted to NaN

If the conversion value is Number

parseInt (10); // 10; if it is an integer value, is output as

parseInt (10.3); // 10; if the decimal, the contents of a decimal point

If the conversion value is the string

the parseInt ( "123"); // 123 ; if it contains only a value, the value is converted to the corresponding

parseInt ( "234.1"); // 234 value after the decimal point omitted;

the parseInt ( "+ 12.1"); // 12 is ; the first sign bit, the rest is a numerical value, converted to an integer

the parseInt ( "+ 2.3. 1"); //. 1 ; the symbol bits appear in other positions, in front of the sign bit of the value retained

the parseInt ( "0xA"); // 10 ; If the value contains only hexadecimal format, converted to the corresponding decimal

parseInt ( "010"); // [Note! ] Will not be parsed as octal, the result is 10

parseInt ( ""); // empty string is converted to NaN

parseInt ( "1 + 2.3") ; // 1; if the first value is sequentially parsing backwards, to find a continuous value, until the first non-numeric, numeric conversion of the previously acquired number of return

parseInt("123ac"); //123;

 

By the parseInt () function transformation, for example:

If the conversion value is null, undefined, boolean , converted to NaN

If the conversion value is Number

parseFloat (10); // 10 ; if it is an integer value, is output as

parseFloat (10.1); //10.1 ; if it is a decimal, decimal places, but if it is 10.0 , the result is 10

If the conversion value is the string

parseFloat ( "123"); // 123 ; if it contains only a value, the value is converted to the corresponding

parseFloat ( "234.1"); //234.1 retention value after the decimal point;

parseFloat ( "+ 12.1"); // 12 is ; the first sign bit, the rest is a numerical value, converted to an integer

parseFloat ( "1 + 2.3") ; // 1 value before the sign bits appear in other positions, retained;

parseFloat ( " 0xA " ); // [Note! ] Will not be resolved as hexadecimal, the result is 0

parseFloat ( "010"); // [Note! ] Will not be parsed as octal, the result is 10

parseFloat ( ""); // empty string is converted to NaN

parseFloat ( "+ 2.3. 1"); //. 1 ; if the first value is sequentially parsing backwards, to find a continuous value, until the first non-numeric, numeric conversion as the previously acquired number Returns

parseFloat("123ac"); //123

 

(2) In addition to null, undefined , the other three types of basic data has a variable toString () function, which can obtain the value of the variable specified string representation , typically use it to convert other types of string type, e.g. :

var a = true;

a.toString(); //"true"

If the variable is a number type, default toString () is a string in decimal format returned value indicates, by passing parameters to be input in binary, octal, hexadecimal, binary string value as well as any active form , e.g. :

var num = 10;

num.toString(); //"10”

num.toString(2); //"1010”

num.toString(8); //"12”

num.toString(16); //"a”

 

String () function is the value may be substantially any other type of data into a string, including null , undefined .

 

(3) any other type of data can be converted to Boolean type, with reference to the conversion table:

 

 

Guess you like

Origin www.cnblogs.com/wodeqiyuan/p/11408503.html