In a recent TypeScript code snippet, I came across the following:
const arrayAA: Record<
someSchema['propX'],
typeof arrayBB
> = {};
for (const varB of arrayBB) {
(arrayAA[someStringValue] ??= []).push(varB)
}
What is the significance of "??=" in this context?
I have not been able to locate any information about "??=" in the official documentation.
==========
(Addendum after receiving input)
It appears that this question has been asked previously (despite my search for "??=" on StackOverflow).
Thus, could this code be reframed as follows:
if (arrayAA[someStringValue] === undefined || arrayAA[someStringValue] === null) {
arrayAA[someStringValue] = [];
}
arrayAA[someStringValue].push(varB)
(Special thanks to Ivar)