Blogger Information
Blog 49
fans 0
comment 3
visits 23042
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
实例演示数据类型与分支及循环
P粉479712293
Original
484 people have browsed it

题目一:实例演示数据类型中的原始类型与引用类型

js文件如下:

  1. // *数据类型
  2. // *1原始类型
  3. // *number类型
  4. let a=100;
  5. console.log(typeof a);
  6. // *string类型
  7. let b='welcome php';
  8. console.log(typeof b);
  9. // *boolean类型
  10. let c=true;
  11. console.log(typeof c);
  12. // *null类型
  13. let d=null;
  14. console.log(typeof d);
  15. // *undefined类型
  16. let e;
  17. console.log(typeof e);
  18. // *2.引用类型
  19. // *a数组类型
  20. const man=['张三',25,'男'];
  21. console.log(man);
  22. console.log(Array.isArray(man));
  23. // *对象类型
  24. const obj={
  25. name:'张三',
  26. age:21,
  27. sex:'男',
  28. };
  29. console.log(obj);
  30. console.log(typeof obj);
  31. // *函数类型
  32. function a1(){
  33. return 'welcome php';
  34. }
  35. console.log(a1());
  36. console.log(typeof a1);

对应的浏览器效果图如下:

题目二:实例演示所有分支与循环类型

js文件如下:

  1. // *单分支
  2. let height=1.2;
  3. if(height>=1.2){
  4. console.log('凭票进场');
  5. }
  6. // *双分支
  7. height=1;
  8. if(height>=1.2){
  9. console.log('凭票进场');
  10. }else{
  11. console.log('免票进场');
  12. }
  13. // *三元操作
  14. height=1.5
  15. let a2=height>=1.2?'凭票进场':'免票进场';
  16. console.log(a2);
  17. // *switch
  18. let age=70;
  19. switch(true){
  20. case age >=1 && age<7:
  21. console.log('免票进场');
  22. break;
  23. case age>=7 &&age<12:
  24. console.log('半票进场');
  25. break;
  26. case age>=12 && age<60:
  27. console.log('全票进场');
  28. break;
  29. case age>=60 && age<70:
  30. console.log('凭身份证半票进场,如无全票进场');
  31. break;
  32. case age>=70 && age<120:
  33. console.log('凭身份证免票进场,如无全票进场');
  34. break;
  35. case (age>0 && age<1) || age>=120:
  36. console.log('不适合的年龄段,不能进场');
  37. break;
  38. default:
  39. console.log('错误数据');
  40. break;
  41. }
  42. // *1while循环
  43. // *常量型数组
  44. const sanguo=['魏国','蜀国','吴国'];
  45. let i=0;
  46. while(i<sanguo.length){
  47. console.log(sanguo[i]);
  48. i++;
  49. }
  50. // *2do-while循环
  51. i=0;
  52. do{
  53. console.log(sanguo[i]);
  54. i++;
  55. }while(i<sanguo.length);
  56. // *3for循环
  57. for(i=0;i<sanguo.length;i++){
  58. console.log(sanguo[i]);
  59. }
  60. // *4for-of循环
  61. for(let item of sanguo){
  62. console.log(item);
  63. }
  64. // *5for-in循环
  65. // *用常量型来表示一个微信群对象
  66. const weixinqun={
  67. obj1:'刘备',
  68. obj2:'关羽',
  69. obj3:'张飞',
  70. obj4:'孔明',
  71. obj5:'赵云',
  72. };
  73. // *用for-in循环来遍历对象:
  74. for(let key in weixinqun){
  75. console.log(weixinqun[key]);
  76. }

对应的浏览器效果图如下:

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
1 comments
P粉479712293 2022-08-08 11:06:49
原因是注解把string写成strong是吗?
1 floor
Author's latest blog post