A study record of advanced programming in JavaScript (i)

Source: Internet
Author: User

Recently began to re-read the "JavaScript Advanced Programming", the memory of this is the third time, but the front is a cursory, this time still need to tidy up and practice.

Although it is a basic concept, but there are a lot of easy to pay attention to the place, do not know its mystery and so many, special record here, to prevent themselves from forgetting, but also to increase their understanding

(1) JavaScript has 5 simple data types: undefined,null,boolean,number,string, a complex data type Object

(2) typeof operator

In JavaScript, typeof and Instanceof are two well-deserved points to keep in mind that typeof is not a function but simply a simple operator, with two points to note:

1:typeof (NULL) returns an object, because null is considered to be an empty objects reference

2:typeof (function) returns function

(3) for null and undefined values, they have a lot in common:

1: When the equality operator is performed on them: alert (null = = undefined) returns True when

The 2:null and undefined data types have only one value, namely null and undefined

3:undefined and Null return FALSE when they are coerced by a Boolean () type conversion

Both 4:null and undefined do not have the ToString () function.

(4) when a Boolean () coercion type is cast, false, "", 0,nan,null,undefined will be converted to false, and the others will be converted to true

(5) Number type

1: Because the memory space required to save the floating-point value is twice times the integer value, JS automatically converts the floating-point number to the integer type (if possible)

2:js in the floating-point operation, there will be low accuracy of the bug, resulting in 0.1+0.2 after not 0.3, so in the floating-point operation to be extra careful

3: Once an operation has +infinity or-infinity, the value will not continue to rub the next calculation, because Infinity is not able to participate in the operation

4: For Nan, any operation that designs Nan will return Nan,nan and any value is unequal, including itself, so when performing the following operation, the return will be false:

Alert (Nan==nan);

5:number () can convert any data type to a numeric type, while parseint and parsefloat can only convert a string to a numeric type

For number,

Number (null); returns 0 Number ("") returns 0

Number (undefined) returns NaN

For parseint,

parseint (""); return Nan

parseint can convert 8 binary and 16 binary values, but in ECMAScript5, parseint does not have the ability to convert 8 binary.

For parsefloat, it can only parse decimal values, so he did not specify the usage of the cardinality with the second argument

(6) Logic and logic or operation

With: 1: The second operand is returned when the first operand is an object

2: A second operand is returned when two operands are objects

3: If there is a Nan operand, null is returned,

4: If one of the operands is undefined, the undefined is returned

When performing the following operation, the return is 2

Alert (1.&&2);

Or: 1: The first operand is returned when the first operand is an object

2: When two operands are objects, the first operand is returned

3: If there is a Nan operand, null is returned,

4: If one of the operands is undefined, the undefined is returned

When performing the following operation, the return is 1

Alert (1| | 2);

(7) Subtraction operator

Multiply: 1:infinity and 0 multiply, the result is Nan

2:infinity and non-0 values are multiplied to return the infinity

Except: 1: If it is 0 by 0, the result is Nan

2:infinity was infinity, the result is Nan

Add: 1:infinity and-infinity Add, the result is Nan

2:+0 and-0 added, resulting in +0

Subtract 1:-infinity and infinity, resulting in Nan

(8) In a function, any code that is behind the return statement will never execute

(9) JS does not overload the function, even if two functions are defined as the same, the next one will always overwrite the previous one



A study record of advanced programming in JavaScript (i)

Related Article

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.