3.类型.html 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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>Document</title>
  7. </head>
  8. <body>
  9. <!--
  10. 弱语言类型
  11. 数据 决定 类型
  12. 检验类型的方法:
  13. typeof xxx
  14. null类型通过typeof会判断成object
  15. js数据类型:
  16. 基本数据类型:
  17. number 数字
  18. string 字符串
  19. null 空
  20. undefined 未定义的
  21. boolean 布尔值(true/false)
  22. 引用数据类型
  23. Object(数组[]/对象{}/函数)
  24. -->
  25. <script>
  26. var a = 10;
  27. console.log(typeof a);//number
  28. var b = '10';
  29. console.log(typeof b);//string
  30. var c = true;
  31. console.log(typeof c);//boolean
  32. var d = false;
  33. console.log(typeof d);//boolean
  34. var e;
  35. console.log(typeof e);//undefined
  36. var f = null; // null
  37. console.log(typeof f);//null类型通过typeof会判断成object
  38. var g = [1,2,3];
  39. console.log(typeof g);
  40. var h = {
  41. name:'小明'
  42. }
  43. console.log(typeof h)
  44. </script>
  45. </body>
  46. </html>