Blogger Information
Blog 20
fans 1
comment 0
visits 17682
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
数组,对象的解构.常用的流程控制方法!
xosing的博客
Original
620 people have browsed it

1.数组与对象的解构

解构要求等号二边类型一致

数组解构

  1. <script>
  2. const cars = ['volvo', ['bmw-x1', 'bmw-x2', 'bmw-x3'], 'benz', ];
  3. [car1, [car2, car3, car4], car5] = cars;
  4. console.log(car1, car2, car3, car4, car5);
  5. </script>

对象解构

  1. <script>
  2. const school = {
  3. name: '城关小学',
  4. class: '二班',
  5. number: 56,
  6. };
  7. ({name,classes,number,} = {name: '城关小学',classes: '二班',number: 56,});
  8. console.log(name, classes, number)
  9. </script>

2.流程控制方法

单分支

  1. <script>
  2. let score = 61;
  3. if (score >= 60) console.log('合格');
  4. </script>

双分支

  1. <script>
  2. let score = 59;
  3. if (score >= 60) console.log('合格');
  4. else console.log('明年再来.加油!')
  5. </script>

多分支

  1. <script>
  2. let score = 104;
  3. if (score >= 60 && score < 80) console.log('合格');
  4. else if (score >= 80 && score <= 100) console.log('优良');
  5. else if (score > 100 || score < 0) console.log('非法分数');
  6. else console.log('明年再来.加油!')
  7. </script>

switch语句用法

  1. <script>
  2. let exam = 'error';
  3. switch (exam) {
  4. case 'fail':console.log('考试失败');break;
  5. case 'success':console.log('考试过关');break;
  6. case 'error':console.log('未参加考试');break;
  7. default:console.log('请输入正确的名字');
  8. }
  9. </script>

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