#JavaScript: The nullish coalescing operator (??) is great for providing default values for missing Map entries:

function incWordCount(wordToCount, word) {
wordToCount.set(word, (wordToCount.get(word) ?? 0) + 1);
}

https://exploringjs.com/impatient-js/ch_undefined-null.html#nullish-coalescing-operator

The non-values `undefined` and `null` • JavaScript for impatient programmers (ES2022 edition)

@rauschma what‘s different to || 0?
The non-values `undefined` and `null` • JavaScript for impatient programmers (ES2022 edition)

@rauschma well but in your example it is to be a number and yes for 0 I’d get in the or case but well that‘s not a problem.
@tomsontom Ah got it, you mean in this particular case:
– It’s good to get into the habit of using this pattern because it’s generally safer.
– ?? makes it slightly more obvious what you are trying to do.
@rauschma yeah in your very sample the result is the same - agree adopting ?? is a good habit