Read a fancy article from Dr. Axel Rauschmayer.
He mentioned about the logical assignment Operators ??=
, &&=
and ||=
.
From my perspective, ??=
could be very useful than the others.
??=
const books = [
{
isbn: '123',
},
{
title: 'ECMAScript Language Specification',
isbn: '456',
},
];
// Add property .title where it’s missing
for (const book of books) {
book.title ??= '(Untitled)';
}
assert.deepEqual(
books,
[
{
isbn: '123',
title: '(Untitled)',
},
{
title: 'ECMAScript Language Specification',
isbn: '456',
},
]);