Conversion between data types and data types

1 Data Type

js data type into basic data types and complex data types

Basic data types

number (numeric type) string (i string type) Boolean (boolean) null (empty) undefined (undefined)
in which the number printed on the console and the true blue
NaN: not a number is not a number (a number type a)
isNaN: judgment is not not a number, if not the figure was true, that figure was false

Complex data types

Object Array Functions

Conversion between the two data types

Number () are converted to digital if not a number returns NaN
parseInt () to an integer if the first one is not a number returns NaN
parseFloat () converted into a floating-point number if the first one is not a number returns NaN
Boolean () converted into Boolean type
toString () into a string

3 detects the data type

1 typeof basic data types may be detected, but encountered complex data types not work
when the object is an array detector
detecting a null object Here Insert Picture Description
2 Object.prototype.toString.call () can detect all types of data
Here Insert Picture Description

Calculation between data types 4

(1) between the string and the sum of all elementary data types are string
Here Insert Picture Description
(2) when added will convert between true boolean type number to 1, false converted to 0
when the addition result is undefined NaN3
Here Insert Picture Description
(. 3 ) when the boolean type addition result is undefined NaN
Here Insert Picture Description
(. 4) in addition to undefined string concatenation string adding the rest are always NaN
Here Insert Picture Description
when subtraction between data types
when the number string and subtraction, if there is a pure string numbers, then the result is a number of digital type, if there is not a pure numeric string, the result is NaN.
when the subtraction is also undefined NaN.
Here Insert Picture Description
first string is determined when the string inside the other types is not purely digital subtraction, If the result is not a pure digital pure digital NaN if, in addition to undefined subtraction is NaN, the rest of all types of digital number
Here Insert Picture Description

Released four original articles · won praise 0 · Views 24

Guess you like

Origin blog.csdn.net/weixin_42638161/article/details/104225654