Blogger Information
Blog 21
fans 0
comment 0
visits 14742
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
(1102)ES6 的基本语法 模板字面量和标签函数 对象和数组的结构
Yuming
Original
570 people have browsed it

(1102)ES6 的基本语法 模板字面量和标签函数 对象和数组的结构

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

  • 模板字面量 更好的拼接变量和字符串
  1. <script>
  2. let name = "张三"; let age = 18; let height = 1.8; const man = `姓名:${name}
  3. ,年龄:${age},身高:${height}`; console.log(man);
  4. </script>

  • 标签函数
  1. <script>
  2. let name = "张三";
  3. let age = 18;
  4. let height = 1.8;
  5. test`姓名:${name},年龄:${age},身高:${height}`;
  6. function test(str, age, height) {
  7. console.log(str); // 字符串类型的数组
  8. console.log(age);
  9. console.log(height);
  10. }
  11. </script>

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

  1. let obj = {
  2. name: "小明",
  3. age: 18,
  4. height: 1.8,
  5. };
  6. // 对象的解构
  7. const { name, age, height } = obj;
  8. console.log(name, age, height);

  1. let arr = [1, 2, 3, 4];
  2. console.log(...arr);
  3. // 数组的解构;
  4. const [a, b, c, d] = arr;
  5. console.log(a, b, c, d);

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