資料類型【js】

來源:互聯網
上載者:User

標籤:type   blog   href   log   xmlns   head   tag   body   asc   

javascript的資料類型:N umberStringBooleanundefined  4種。
類型的總結:所有的數值都是number類型字元和字串都是string類型布爾是boolean類型如果一個變數沒有初始化值的時候,其類型為undefined類型。表示沒有定義。
typeof 可以查看變數的資料類型。 使用格式:typeof 變數名  或者    typeof(變數名)
案例代碼:
 
  1. <!DOCTYPE html>
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>javascript資料類型</title>
  6. <script type="text/javascript">
  7. /*
  8. javascript的資料類型:
  9. numberstringbooleanundefined 共4種。
  10. 類型的總結:
  11. 所有的數值都是number類型
  12. 字元和字串都是string類型
  13. 布爾是boolean類型
  14. 如果一個變數沒有初始化值的時候,其類型為undefined類型。表示沒有定義。
  15. typeof可以查看變數的資料類型。
  16. 使用格式:
  17. typeof 變數名
  18. */
  19. document.write("10資料類型是:" + (typeof 10) + "<br/>");
  20. document.write("9.99資料類型是:" + (typeof 9.99) + "<br/>");
  21. document.write("‘a‘資料類型是:" + (typeof ‘a‘) + "<br/>");
  22. document.write("‘abc‘資料類型是:" + (typeof ‘abc‘) + "<br/>");
  23. document.write("\"abcdef\"資料類型是:" + (typeof "abcdef") + "<br/>");
  24. document.write("true資料類型是:" + (typeof true) + "<br/>");
  25. document.write("a資料類型是:" + (typeof a) + "<br/>");
  26. </script>
  27. </head>
  28. <body>
  29. </body>
  30. </html>
結果如下:  

來自為知筆記(Wiz)

資料類型【js】

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.