xgqfrms™, xgqfrms® : xgqfrms's offical website of cnblogs! xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!

s ?? nullish coalescing operator and ??= nullish coalescing assignment All In One

js ?? nullish coalescing operator and ??= nullish coalescing assignment All In One

Nullish coalescing assignment (??=)
空值合并赋值 (??=)

Nullish coalescing operator (??)
空值合并运算符 (??)

Logical nullish assignment (??=)

逻辑无效赋值 (??=)

const obj = { duration: 50 };

obj.duration ??= 10;
console.log(a.duration);
// 50

obj.speed ??= 25;
console.log(a.speed);
// 25


obj = {};
// {}
obj['k'] ??= {};
// {}
obj;
// {k: {…}}

obj = {};
// {}
obj['k'] = obj['k'] ?? {};
// {}
obj;
// {k: {…}}

demos

refs

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Logical_nullish_assignment

Nullish coalescing assignment (??=)
空合并赋值 (??=)

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Nullish_coalescing_operator
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Nullish_coalescing

Nullish coalescing operator (??)
空合并运算符 (??)

https://developer.mozilla.org/en-US/docs/Glossary/Nullish

https://twitter.com/harshbothra_/status/1485485358922211328/photo/1



©xgqfrms 2012-2020

www.cnblogs.com/xgqfrms 发布文章使用:只允许注册用户才可以访问!

原创文章,版权所有©️xgqfrms, 禁止转载 🈲️,侵权必究⚠️!


posted @ 2022-01-24 23:30  xgqfrms  阅读(52)  评论(1编辑  收藏  举报