(1)解構賦值
解構賦值允許你從陣列或物件中提取資料,並賦值給變數
陣列解構
let [first, second, third] = ["red", "green", "blue"];
console.log(first); // 輸出: red
console.log(second); // 輸出: green
console.log(third); // 輸出: blue
物件解構
let person = {name: "John", age: 30};
let {name, age} = person;
console.log(name); // 輸出: John
console.log(age); // 輸出: 30
(2)模板字串
模板字串使用反引號來創建,並且可以在字串中嵌入變數和表達式
let name = "Alice";
let greeting = `Hello, ${name}!`;
console.log(greeting); // 輸出: Hello, Alice!
(3)展開運算符
展開運算符(...)允許你將陣列或物件展開
展開陣列
let arr1 = [1, 2, 3];
let arr2 = [...arr1, 4, 5, 6];
console.log(arr2); // 輸出: [1, 2, 3, 4, 5, 6]
展開物件
let obj1 = {a: 1, b: 2};
let obj2 = {...obj1, c: 3};
console.log(obj2); // 輸出: {a: 1, b: 2, c: 3}