Boolean data type conversion of the mandatory and other hexadecimal numbers

(I) the mandatory conversion

1. definitions : refers to a data type cast to other data types

   Mainly refers to the type of conversion, the other types of data, converted to a String, Number, Boolean

 

(Ii) to convert other data types for other hex numbers

1. JS, if necessary represents a hexadecimal number, it is necessary to 0x beginning

                  If you need to represent octal numbers, you need to 0 at the beginning

                  If you need to represent binary numbers, you need to 0b beginning, but not all browsers support

Specific examples:

It indicates hexadecimal numbers

 

 Represent octal numbers

 

 Represent binary numbers

 

2. to "070" this string , some browsers as octal resolved, some will be resolved as a decimal

Google Chrome

 

 IE 8 browser

 

3 may be the parseInt () passing a second parameter to the specified number hexadecimal

Octal

 Converted to decimal

 

 

(Iii) converting the other data type Boolean type

Using Boolean () function

                      - Digital ----> Boolean

                                - In addition to 0 and NaN , the rest are true

                      - string ----> Boolean

                                - In addition to the empty string , the rest are true

                     - null and undefined are converted to false

                     - the object will be converted to true

Specific examples:

- Digital ----> Boolean

Digital 123; true

 Digital -456; true

 Digital 0; false

 Indinity ;   true

 NaN; false

 

- string ----> Boolean

"hello"  ;   true

 

 "true"   ;  true

 

 "false"  ;  true

 

"Error"; true

 

"" Empty string; to false

 

 "" Space; true

 

- null and undefined are converted to false

null  ;  false

 undefined  ;  false

 

 

 

These are the mandatory conversion of all content, want to help.

Guess you like

Origin www.cnblogs.com/shihaiying/p/11877761.html