js ??= operator All In One


js ??= operator All In One

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: {…}}

refs

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

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

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

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


Flag Counter

?xgqfrms 2012-2020

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

原创文章,版权所有??xgqfrms, 禁止转载 ???,侵权必究??!