Blogger Information
Blog 7
fans 0
comment 1
visits 4286
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
1102作业 1. 实例演示模板字面量与标签函数 2. 实例演示对象与数组的解构
Vic
Original
553 people have browsed it

实例演示模板字面量与标签函数

  1. <!DOCTYPE html>
  2. <html lang="">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>Document</title>
  7. </head>
  8. <body>
  9. <script>
  10. var a = 2;
  11. var b = 3;
  12. var c = `a的值: ${a} b的值:${b} a*b的值: ${a * b}`;
  13. console.log(c);
  14. function test(obj, val1, val2){
  15. console.log(obj)
  16. console.log(val1)
  17. console.log(val2)
  18. let total =`${obj[0]}${val1},${obj[1]}${val2},${obj[2]}${val1 * val2}`;
  19. console.log(total)
  20. }
  21. let result = test`a的值: ${a} b的值:${b} a*b的值: ${a * b}`;
  22. </script>
  23. </body>
  24. </html>

反馈效果:


实例演示对象与数组的解构

  1. <!DOCTYPE html>
  2. <html lang="">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>Document</title>
  7. </head>
  8. <body>
  9. <script>
  10. // 对象解构
  11. const user = {
  12. id: "abc",
  13. password: 123456,
  14. };
  15. ({ id, password } = user);
  16. console.log(id, password);
  17. // 不完全解构
  18. ({id, password, phone_number} = user);
  19. console.log(id, password, phone_number);
  20. // 默认值
  21. ({id, password, phone_number = "无"} = user);
  22. console.log(id, password, phone_number);
  23. //数组解构
  24. const height = [170, 175, 180, 188];
  25. let [zhangsan,lisi,wangwu,zhoujielun] = height;
  26. console.log(zhangsan,lisi,wangwu,zhoujielun);
  27. //数组解构交换变量
  28. let a = 1;
  29. let b = 2;
  30. [a,b] = [b,a]
  31. console.log(a,b);
  32. </script>
  33. </body>
  34. </html>

反馈效果:

Correcting teacher:天蓬老师天蓬老师

Correction status:qualified

Teacher's comments:var与let建议不要混用
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