leetcode 2619
遇到了 ?? 語法糖,簡而言之
- 可選鏈功能
就是防止拋出異常
caught TypeError: Cannot read properties of undefined (reading 'salary')
at <anonymous>:1:12
const user = {name:'11',age:'22'}
user.write.salary()
== 拋出錯誤
user.write?.salary()
== 顯示undefined
- 空值凝聚
const value1 = 0 || 'default string';
console.log(value1);
const value2 = '' || 1000;
console.log(value2);
const value1 = 0 ?? 'default string';
console.log(value1);
const value2 = '' ?? 1000;
console.log(value2);
- 報錯凝聚?
return this[this.length - 1] ?? -1
如果this.length == 0 的話原先會拋出錯誤現在不會了