Blogger Information
Blog 25
fans 1
comment 1
visits 17303
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
0225作业+JS数据类型+10期线上班
江川林
Original
796 people have browsed it

JS数据类型

-number数值,包括整数和小数
-string字符串,由单引号或双引号包裹的代码
-boolean布尔值,只有true和false
-object对象,有{}包裹,对象的键名,称为属性,属性可以为数组,对象,字符串等
-function函数,由function声明
-array数组
-undefined未定义的
-null空值

在JS中,任意变量均是对象
我们只有知道数据类型之后,才能判断数据的值,并做出后续的操作

常用类型的类型检测

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>Title</title>
  6. </head>
  7. <body>
  8. <script>
  9. // 字符串:用单引号或双引号包裹
  10. var a = 'a';
  11. // console.log(typeof a);
  12. // 数值:整数和小数
  13. a = 2;
  14. console.log(typeof a);
  15. // 布尔值:true/false
  16. // 数组
  17. // var b = Array(1,2);
  18. var b = [1,2];
  19. // console.log(typeof b);
  20. console.log(Array.isArray(b));
  21. // 对象:由花括号分隔
  22. var object = {name:'小江',id:20,'sex':'男'};
  23. // console.log(typeof object);
  24. // console.log(object);
  25. // console.log(object['sex']);
  26. // console.log(object.id);
  27. // 检测函数
  28. function f(c, d) {
  29. return c+d;
  30. }
  31. // console.log(typeof f(1,2));
  32. // 检测NULL值
  33. var a = null;
  34. console.log(typeof null)
  35. if (typeof a !== 'undefined'&& !a){
  36. console.log('a的值是NULL');
  37. }
  38. console.log(NAN === NAN);
  39. </script>
  40. </body>
  41. </html>
Correcting teacher:天蓬老师天蓬老师

Correction status:qualified

Teacher's comments:继续努力
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments