(1102)ES6 的基本语法 模板字面量和标签函数 对象和数组的结构
实例演示模板字面量与标签函数
<script>
let name = "张三"; let age = 18; let height = 1.8; const man = `姓名:${name}
,年龄:${age},身高:${height}`; console.log(man);
</script>
<script>
let name = "张三";
let age = 18;
let height = 1.8;
test`姓名:${name},年龄:${age},身高:${height}`;
function test(str, age, height) {
console.log(str); // 字符串类型的数组
console.log(age);
console.log(height);
}
</script>
实例演示对象与数组的解构
let obj = {
name: "小明",
age: 18,
height: 1.8,
};
// 对象的解构
const { name, age, height } = obj;
console.log(name, age, height);
let arr = [1, 2, 3, 4];
console.log(...arr);
// 数组的解构;
const [a, b, c, d] = arr;
console.log(a, b, c, d);