Blogger Information
Blog 47
fans 1
comment 0
visits 40563
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
常用数据类型,分支与循环类型
新手1314
Original
676 people have browsed it

常用数据类型(原始类型)

1.number:数值类型

2.string:字符串类型

3.Boolean:布尔类型

4.undefined:代表无,未定义类型

5.null:代表空。

常用数据类型(引用类型)

1.array:数组类型

2.object:对象类型

3.function:函数类型

js代码:

  1. <script>
  2. //原始类型:1.数值类型
  3. console.log("数值类型");
  4. let a = 100;
  5. console.log(typeof a);
  6. console.log("------------");
  7. //2.字符串类型
  8. console.log("字符串类型");
  9. let b = "数据类型";
  10. console.log(typeof b);
  11. console.log("------------");
  12. //3.布尔类型
  13. console.log("布尔类型");
  14. let c = true;
  15. console.log(typeof c);
  16. console.log("------------");
  17. //4. undefined类型
  18. console.log("undefined类型");
  19. let d;
  20. console.log(typeof d);
  21. console.log("------------");
  22. //5.null类型
  23. console.log("null类型");
  24. let e = null;
  25. console.log(typeof e);
  26. console.log("------------");
  27. //引用类型 1.数组类型
  28. console.log("数组类型");
  29. let f = ["1", "2"];
  30. console.log(typeof f);
  31. //判断一个函数是否是数组
  32. console.log(Array.isArray(f));
  33. console.log("------------");
  34. //2.对象类型
  35. console.log("对象类型");
  36. let g = { name: "对象", password: "123456" };
  37. console.log(typeof g);
  38. console.log("------------");
  39. //3.方法类型
  40. console.log("函数类型");
  41. function i() {}
  42. function h() {
  43. return typeof i;
  44. }
  45. console.log(h(i));
  46. console.log("------------");
  47. </script>

分支与循环类型

1.if:单分支

  1. <script>
  2. let age = 18;
  3. if ((agr = 18)) {
  4. console.log("这是单分支");
  5. }
  6. </script>

2.if else :多分支

  1. let ceshi = 5;
  2. if (ceshi > 6) {
  3. console.log("这是if多分支");
  4. } else {
  5. console.log("这是else多分支");
  6. }

3.if , else if , else :多分支

  1. let fenzhi = 5;
  2. if (ceshi > 6) {
  3. console.log("这是if多分支");
  4. } else if ((ceshi = 5)) {
  5. console.log("这是else if多分支");
  6. } else {
  7. console.log("这是else多分支");
  8. }

4.switch:多分支语法糖

  1. let yufatang = 18;
  2. switch (true) {
  3. case yufatang >= 19:
  4. console.log("这是大于18时的输出");
  5. break;
  6. case yufatang == 18:
  7. console.log("这是等于18时的输出");
  8. break;
  9. default:
  10. console.log("这是小于18时的输出");
  11. }

5.while循环

  1. let a = 1;
  2. while (a <= 9) {
  3. console.log(a);
  4. a++;
  5. }

6.do while 循环:

  1. let a = 1;
  2. do {
  3. console.log(a);
  4. a++;
  5. } while (a <= 9);

7.for 循环:

  1. for (let i = 1; i <= 10; i++) {
  2. console.log("这是For循环" + i);
  3. }

8.for of循环:(可以通过此种方式查看数组的值)

  1. let arr = ["for-of的值1", "for-of的值2", "for-of的值3"];
  2. for (let name of arr) {
  3. console.log("值:" + name);
  4. }

9.for in循环:(可以通过次方式遍历得到对象的值)

  1. let obje = {
  2. username: "新手1314",
  3. password: "123456",
  4. type: "确定",
  5. };
  6. for (let zhi in obje) {
  7. console.log(obje[zhi]);
  8. }

Correcting teacher:PHPzPHPz

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
Author's latest blog post