Blogger Information
Blog 62
fans 3
comment 1
visits 29688
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
js数据类型与分支
kiraseo_wwwkiraercom
Original
333 people have browsed it

js数据类型与分支

实例演示常用数据类型,特别是引用类型

演示代码如下

  1. let a = 'abc';
  2. console.log("++++string 数据类型+++++");
  3. console.log(typeof a);
  4. console.log("++++++++++++++++++++++++++++");
  5. let b = 123;
  6. console.log("++++number 数据类型+++++");
  7. console.log(typeof b);
  8. console.log("++++++++++++++++++++++++++++");
  9. let c = ['Apple' , 'Pear' , 'Banana'];
  10. console.log("++++array 数据类型+++++");
  11. console.log(typeof c);
  12. console.log("++++++++++++++++++++++++++++");
  13. let d = {
  14. id:1,
  15. name: 'kira',
  16. num:61952,
  17. }
  18. console.log("++++object 数据类型+++++");
  19. console.log(typeof d);
  20. console.log("++++++++++++++++++++++++++++");
  21. console.log("2. 实例演示所有分支与循环类型 ");
  22. console.log("++++for循环方式+++++");

输出效果

输出效果

实例演示所有分支与循环类型

演示代码如下

  1. console.log("2. 实例演示所有分支与循环类型 ");
  2. console.log("++++for循环方式+++++");
  3. for(let i=0; i< c.length; i++){
  4. console.log( c[i] );
  5. }
  6. console.log("++++++++++++++++++++++++++++");
  7. console.log("++++ for -in循环方式+++++");
  8. for(let item in d ){
  9. console.log( item+":"+d[item] );
  10. }
  11. console.log("++++++++++++++++++++++++++++");
  12. console.log("++++多分支+++++");
  13. let age = 128;
  14. if(age >=18 && age<35){
  15. console.log('可以吃糖啦!');
  16. }
  17. else if(age >=35 && age<50){
  18. console.log('建议少吃糖!');
  19. }
  20. else if(age<18 || age >60){
  21. console.log('不能吃糖!');
  22. }
  23. else{
  24. console.log('不建议吃糖!');
  25. }
  26. console.log("++++++++++++++++++++++++++++");
  27. console.log("++++++单分支+++++++");
  28. let scores = 60;
  29. if(scores>=60){
  30. console.log('您的分数及格啦!!!');
  31. }
  32. console.log("++++++++++++++++++++++++++++");
  33. scores = 55;
  34. if(scores>=60){
  35. console.log('您的分数及格啦!!!');
  36. }else{
  37. console.log('不及格啦,要多加强学习啦!!!');
  38. }

输出效果

输出效果

完整代码如下

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <title>Document</title>
  8. </head>
  9. <body>
  10. <script>
  11. // 1. 实例演示常用数据类型,特别是引用类型
  12. console.log("实例演示常用数据类型,特别是引用类型 ");
  13. let a = 'abc';
  14. console.log("++++string 数据类型+++++");
  15. console.log(typeof a);
  16. console.log("++++++++++++++++++++++++++++");
  17. let b = 123;
  18. console.log("++++number 数据类型+++++");
  19. console.log(typeof b);
  20. console.log("++++++++++++++++++++++++++++");
  21. let c = ['Apple' , 'Pear' , 'Banana'];
  22. console.log("++++array 数据类型+++++");
  23. console.log(typeof c);
  24. console.log("++++++++++++++++++++++++++++");
  25. let d = {
  26. id:1,
  27. name: 'kira',
  28. num:61952,
  29. }
  30. console.log("++++object 数据类型+++++");
  31. console.log(typeof d);
  32. console.log("++++++++++++++++++++++++++++");
  33. console.log("2. 实例演示所有分支与循环类型 ");
  34. console.log("++++for循环方式+++++");
  35. for(let i=0; i< c.length; i++){
  36. console.log( c[i] );
  37. }
  38. console.log("++++++++++++++++++++++++++++");
  39. console.log("++++ for -in循环方式+++++");
  40. for(let item in d ){
  41. console.log( item+":"+d[item] );
  42. }
  43. console.log("++++++++++++++++++++++++++++");
  44. console.log("++++多分支+++++");
  45. let age = 128;
  46. if(age >=18 && age<35){
  47. console.log('可以吃糖啦!');
  48. }
  49. else if(age >=35 && age<50){
  50. console.log('建议少吃糖!');
  51. }
  52. else if(age<18 || age >60){
  53. console.log('不能吃糖!');
  54. }
  55. else{
  56. console.log('不建议吃糖!');
  57. }
  58. console.log("++++++++++++++++++++++++++++");
  59. console.log("++++++单分支+++++++");
  60. let scores = 60;
  61. if(scores>=60){
  62. console.log('您的分数及格啦!!!');
  63. }
  64. console.log("++++++++++++++++++++++++++++");
  65. scores = 55;
  66. if(scores>=60){
  67. console.log('您的分数及格啦!!!');
  68. }else{
  69. console.log('不及格啦,要多加强学习啦!!!');
  70. }
  71. </script>
  72. </body>
  73. </html>

完整输出效果

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