javascript are weakly type, value, comprising: numbers, strings, Boolean values, and, c ++ and java are strong type; int a = "a", string a = "a" being given; var a; primitive types: boolean number number string string value Boolean undefind null, objects Object, the original values are grouped together; 1. Object system comes into an object, an array, a custom function 2. {} eg three courses => 60 61 62; var a = [60,61 62] index number 0, increment ++, a [0] = 60
1 <!DOCTYPE html> 2 <html lang="en"> 3 <head> 4 <meta charset="UTF-8"> 5 <meta name="viewport" content="width=device-width, initial-scale=1.0"> 6 <title>下标获取数值</title> 7 <script> 8 // var a=[60,61,62] 9 // undefined 10 // a[0] 11 // 60 12 // a[1] 13 // 61 14 // a[2] 15 // 62 16 // a[0]=90 17 // 90 18 // a[0] 19 // 90 20 </script> 21 </head> 22 <body> 23 </body> 24 </html>
Array: the primitive type lined up in the order, the array can have anything inside, primitive type
1 <!DOCTYPE html> 2 <html lang="en"> 3 <head> 4 <meta charset="UTF-8"> 5 <meta name="viewport" content="width=device-width, initial-scale=1.0"> 6 <title>数组,原始类型</title> 7 <script> 8 // var a [0,"string",false] 9 // Uncaught SyntaxError: Unexpected token [ 10 // var a=[0,"string",false] 11 // undefined 12 // a[0] 13 // 0 14 // a[1] 15 // "string" 16 // a[2] 17 // false 18 </script> 19 </head> 20 <body> 21 </body> 22 </html>
Custom object var a1 = 60; var a2 = 61; var a3 = 62; var a = { "a1": 60, "a2": 61, "a3": 62} string representing number var a = {0: 60,1: 61,2: 62} in this array type custom made based on sorting, omitting 0
1 <!DOCTYPE html> 2 <html lang="en"> 3 <head> 4 <meta charset="UTF-8"> 5 <meta name="viewport" content="width=device-width, initial-scale=1.0"> 6 <title>自定义对象</title> 7 <script> 8 // var a1=60; 9 // var a2=61; 10 // var a3=62; 11 // var a={"a1":60,"a2":61,"a3":62} 12 // //字符串代表序号 13 // var a={"a1":60,"a2":61,"a3":62} 14 // undefined 15 // a["a1"] 16 // 60 17 // a["a2"] 18 // 61 19 // a["a3"] 20 // 62 21 22 var a={2:60,3:61,4:62} 23 var a={2:60,3:61,4:62} 24 undefined 25 a[2] 26 60 27 a[3] 28 61 29 </script> 30 </head> 31 <body> 32 </body> 33 </html>
var a; => undefind var a = null; null object so many different types of data, it is determined by what method? typeof () to help see the data type
1 <!DOCTYPE html> 2 <html lang="en"> 3 <head> 4 <meta charset="UTF-8"> 5 <meta name="viewport" content="width=device-width, initial-scale=1.0"> 6 <title>typeof()查看数据类型</title> 7 <script> 8 var a; 9 undefined 10 typeof(a) 11 "undefined" 12 a=1; 13 1 14 typeof(a) 15 "number" 16 a="a"; 17 "a" 18 typeof(a) 19 a=false 20 false 21 typeof(a) 22 "boolean" 23 a=[1]; 24 [1] 25 typeof(a) 26 "object" 27 a=null; 28 null 29 typeof(a) 30 "object" 31 var a="1111"; 32 undefined 33 typeof(a) 34 "string" 35 var b=Number(b) 36 undefined 37 typeof(b) 38 "number" 39 a=1 40 1 41 b=String(a) 42 "1" 43 typeof(a) 44 "number" 45 typeof(b) 46 "string" 47 </script> 48 </head> 49 <body> 50 </body> 51 </html>
Data type conversion? Original Type: string number number string Boolean Boolean "aaa" => digital number display converter var a = 7; var b = number (a); strong conversion 1+ "1" => "11"