.? ?? es2020

 

1:安装依赖  yarn add  @babel/plugin-proposal-optional-chaining

 

2:在babel.config.js中  的 plugins中添加 "@babel/plugin-proposal-optional-chaining"

 

 注意:不可以赋值

 

.?可选链操作符

如果可选链操作符任意一环是null/undefined,表达式将会短路计算直接返回undefined

 

 

空位合并操作符(Nullish coalescing Operator)

如果表达式在??的左侧运算符求值为 undefined 或 null,就返回其右侧默认值。排除了0 '' false

let c = a ?? b; 等价于let c = a !== undefined && a !== null ? a : b;

 

posted on 2020-11-20 12:35  章画  阅读(90)  评论(0编辑  收藏  举报

导航