JavaScript學習進度
阿新 • • 發佈:2020-08-11
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <meta charset="utf-8" /> 5 <meta name="viewport" content="width=device-width, initial-scale=1"> 6 <title>1</title> 7 </head> 8 <body> 9 您可以在字串中使用引號,只要不匹配包圍字串的引號即可: 10<script type="text/javascript"> 11 var carname = "Volvo XC60"; 12 var carname = 'Volvo XC60'; 13 var answer1 = 'It\'s alright'; 14 var answer2 = "He is called \"Johnny\""; 15 var answer3 = 'He is called"Johny"'; 16 document.write(carname1 + "<br>") 17 document.write(carname2 + "<br>") 18 document.write(answer1 + "<br>") 19 document.write(answer2 + "<br>") 20 document.write(answer3 + "<br>") 21 22 </script> 23 --> 24 極大或極小的數字可以通過科學(指數)計數法來書寫: 25 <script type="text/javascript"> 26 var x1 = 34.00; 27 var x2 = 34; 28 var y = 123e5;29 var z = 123e-5; 30 document.write(x1 + "<br>") 31 document.write(x2 + "<br>") 32 document.write(y + "<br>") 33 document.write(z + "<br>") 34 </script> 35 36 下面的程式碼建立名為 cars 的陣列: 37 <script type="text/javascript"> 38 var i; 39 var cars = new Array(); 40 cars[0] = "Saab"; 41 cars[1] = "Volvo"; 42 cars[2] = "BMW"; 43 44 for (i =0; i<cars.length; i++) 45 { 46 document.write(cars[i] + "<br>"); 47 } 48 </script> 49 50 物件屬性有兩種定址方式: 51 <script type="text/javascript"> 52 var person = 53 { 54 firstname : "John", 55 lastname : "Doe", 56 id : 5566 57 }; 58 document.write(person.lastname + "<br>"); 59 document.write(person["lastname"] + "<br>"); 60 </script> 61 Undefined 這個值表示變數不含有值。 62 63 可以通過將變數的值設定為 null 來清空變數。 64 <script type="text/javascript"> 65 var person; 66 var car = "Volvo"; 67 document.write(person + "<br>"); 68 document.write(car + "<br>"); 69 var car = null 70 document.write(car + "<br>"); 71 </script> 72 73 </body> 74 </html>