JS-03- basic data type conversion

. 1 <! DOCTYPE HTML>
 2 <HTML>
 . 3      <head>
 . 4          <Meta charset = "UTF-. 8">
 . 5          <title> </ title>
 . 6      </ head>
 . 7      <body>
 . 8        <-! JavaScript basic data type
 . 9        typeof function to get the type of a variable;
 10            Boolean : if the variable is a Boolean type
 . 11            Number: Number If the variable is type (integer, floating point)
 12 is            String: if the variable of type String (a " ',' ')
 13 is            Object: If the variable is a reference type or Null type
 14                         , such as: new new the Array () / new new String () ...
15            function : Function Type
 16            undefined: if the variable is type Undefined ->
 . 17        <Script>
 18 is              var B = to true ;
 . 19              var B = 33 is ;
 20 is              var A = 'ABC' ;
 21 is              var A = "ABC" ;
 22 is              var Aa = 'the I Love "BIA BIA"' ;
 23 is              var obj = {name: 'zhangsan', Sex: 18 is };
 24              var List = [1,2,3,4 ];
 25              var OBJ1 = null ;
 26 is              Alert ( typeof(B));
 27              // print the results to the console 
28              the console.log ( typeof (B));
 29              the console.log (A, typeof (A));
 30              the console.log (Aa);
 31 is              the console.log (obj, typeof (obj));
 32              the console.log (List, typeof (List));
 33 is              the console.log (OBJ1, typeof (OBJ1));
 34 is        </ Script>    
 35        ! <- the JavaScript data converter
 36                Number The (): turn a strong value (including integer and floating point)
 37                *parseInt (): Strong to Integer
 38 is                * parseFloat (): Strong float switch   
 39                Boolean (): boolean value into strong (only the empty string, null (null belong to the object), Number type 0, NaN only for the type of to false)
 40                isNaN (): detecting whether a number is not NaN: not a number (Note: if the number of returns false, the number of type string also returns ture) ->
 41 is         <Script>
 42 is              // Note: contain any string when a non-numeric character represented by 
43 is              //         Number the () returns NaN3 
44 is              //         the parseInt () and parseFloat () returns a value of 
45              
46 is              var STR = '1a123'; // character 
47              var Number = RES (STR); // turn a Number 
48              var res1 = parseInt(str);
49             var res2 = parseFloat(str);
50             console.log(res,typeof(res));
51             console.log(res1,typeof(res1));
52             console.log(res2,typeof(res2));
53             console.log(str,isNaN(str));
54        </script>
55     </body>
56 </html>

 

Guess you like

Origin www.cnblogs.com/qinqin-me/p/11264293.html