[Js Master Road Part 1] Hundreds of JavaScript cases [New Edition] _3 Types of javascript variables

 

JavaScript data types

 

String, Number, Boolean, Array, Object, Null, Undefined

 

1 <!DOCTYPE html>
 2 <html>
 3 <head lang="en">
 4      <meta charset="UTF-8">
 5      <title></title>
 6      <script>
 7          // The type of the variable is determined by the variable 
8          // Weakly typed languages 
​​9  
10          // String types, those in quotes are called string types 
11          //         var userName = "ghostWu"; 
12          //         var userName= 'ghostWu'; 
13          // How to check the type of a variable14 
// typeof          + the name of the variable15 // alert( typeof         userName );//string161718
         
 
 
         //         var age = 20; 
19          //         alert(typeof age); //number(numeric type) 
20  
21          //         var n = 0.2; 
22          //         alert( typeof n ); 
23  
24  
25          // boolean ( true /false ) 
26          //         var a = true; 
27          //         alert( true ); 
28          //         alert( typeof true ); //boolean 
29          //         var a = false; 
30          //         alert( typeof a ); // boolean 
31  
32          //         var a = 'true'; //string 
33          //        var a = 'false'; //string 
34          //         alert( typeof a ); 
35  
36  
37          // object: object, a thing... 
38  //         var a = document; 
39  //         alert( typeof a ); //object(object) 
40  
41  //         var a; 
42  //         alert( a ); //When declaring a variable, no value is given, then its value is undefined 
43  //         alert( typeof a ); //type (undefined); 
44  
45  
46  //         var a = null; 
47  //         alert( a ); 
48  //         alert( typeof null ); //null object 
49 
50 
51 
52         var a = 10;
53         a = '你好';
54         alert( typeof a );
55 
56 
57 
58 
59     </script>
60 </head>
61 <body>
62 
63 </body>
64 </html>

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325331991&siteId=291194637
Recommended