Redo JS Virtuoso Second bomb: data type and type conversion

Source: Internet
Author: User

A data type

Data types in 1 JS

1.1 Data Type Enumeration

1) Number Type

2) Boolean type

3) String type

4) Object Type

5) function type

6) Undefined type

1.2 Data type Acquisition

typeof: Note that this is not a function, but an operator, how to use it? typeof ' ASD ' Result: string

2 various types of explanations

2.1 Number Type

2.1.1 Concept understanding: That is, all real numbers, including integral type, floating point type, this is very well understood, but there is a special case

The 2.1.2 Special Nan:nan itself is a number type, but does not know what its value is, Nan is often due to a type conversion or function return value, such as converting the string ' AA ' to number nature does not know what value he should be after the conversion to use Nan to represent

How special is Nan,

(1) NaN himself did not wait for himself, Nan==nan: The structure is false, you say special not

(2) Determine whether a variable is Nan and can only use the isNaN () function to judge, here for a variable is not Nan, in the isNaN () function, in fact, if the variable is not number is first converted to number, for which the natural conversion to Nan is true, You say special no, then how to convert, change the rules?

A Boolean true directly to 1 false to 0

B string is followed by the first character if the first fails returns Nan directly

C parseint (), parsefloat () conversion for different special cases, respectively

The D object first invokes the object's valueof () return value for conversion

E Undefined,null Direct conversion to Nan

2.1.3 Number range, Number.max_value,number.min_value, how to judge a value between the maximum and minimum values using the Isfinite () function,

For infinity or infinity, use infinity to indicate if negative infinity is preceded by a minus sign '-'

2.2 Boolean type

Only true false two value, true and false are not equal for JS case sensitivity

2.2.1 Type conversions

1) The number type is greater than 0 and is converted to true, whereas false

2) string evaluates String.Length property length, greater than 0 is true and false

3) object is not empty, that is true and false

4) Undefined,nan are false

2.3 String Type

2.3.1 Convert to String

1) Use the ToString () method, but there are 2 special for variable types known cases are not this method, that is, null and undefined, such as Var r=null, R. Without the ToString () method, the ToString () method can be used for a function or conversion after the operation does not know what the return value is, such as

function convert () {return null};var rs=convert (); Rs.tostring () result is null

2) Boolean converted to a string, true result is ' true ', corresponding false is ' false '

2.4 Function type

function is Object

2.5 Object Types

The object in JS is a combination of a set of variables and functions, so the object type is actually a combination of simple types. The corresponding conversion has also been mentioned in the preceding

Two-type conversions

In the above data type conversion also basically refers to the type conversion rules, JS in these rules are fine, this is JS than strong type language such as C#,java to trouble a little bit of the place

Three operators

3.1 js in the operator roughly the same as C # and Java, there is a special operator = = and = = =

= =: means comparing two variables, not comparing two variable types, but converting them to the same type of results, then comparing them. This one of the conversion rules, more than

= = = Also known as the equality operator, meaning two objects first to the same type, and the result is the same, if the use = = = First to determine the same type and then compare the results, if the type is different then directly return false,=== in the comparison of objects more common

3.2 Special

Nan and Nan are not equal, i.e. Nan==nan:false

Undefined is equal to null, the interpretation in JS is undefined inherits from NULL, very special, that is, undefine==null, the result is true

nan==undefined result is False

Redo JS Virtuoso Second bomb: data type and type conversion

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.