?? 这个和 || 几乎一样,但是它不会屏蔽掉 false和 0,当等于0、false也会返回0、false

 ?? 左边的值是 null 或者 undefined,那么就返回右边的值

JS 新语法「可选链」「双问号」

 ?.

引用为空 (null 或者 undefined) 的情况下不会引起错误,该表达式短路返回值是 undefined

const result = response?.settings?.n ??100

如果 response 或者 response.settings 或者 response.settings.n 不存在(值为 null 或者 undefined)时,此时可选链返回undefined,通过??运算符 result 保底值为 100。 

相关文章:

  • 2022-03-05
  • 2021-12-28
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-09
  • 2021-05-25
  • 2021-06-23
猜你喜欢
  • 2021-05-26
  • 2022-12-23
  • 2021-11-02
  • 2021-05-20
  • 2021-10-17
  • 2022-12-23
  • 2021-09-07
相关资源
相似解决方案