可選鍊【?.】
允許讀取對象深層次的屬性的值。
const obj = {
info: {
name: "duxin",
money: 1000
}
}
const testObj = obj?.info?.age;
if (testObj) {
console.log(testObj);
}
空值合并運算符【??】
當左側操作數為null或者undefined時,傳回右側操作數,否則傳回左側操作數。
const variable = undefined;
console.log(variable ?? "===");
邏輯空指派【??=】
左側操作符為null或者undefined的時候,給它指派。