码迷,mamicode.com
首页 > Web开发 > 详细

数据类型【js】

时间:2016-10-23 21:14:40      阅读:167      评论:0      收藏:0      [点我收藏+]

标签:type   blog   href   log   xmlns   head   tag   body   asc   

javascript的数据类型:
Number String Boolean undefined  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. number string boolean undefined 共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>
结果如下:
技术分享
 
 




数据类型【js】

标签:type   blog   href   log   xmlns   head   tag   body   asc   

原文地址:http://www.cnblogs.com/itMiracle/p/5990752.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!