Skip to main content

Command Palette

Search for a command to run...

Nullish coalescing operator ?? example

Published
1 min readView as Markdown

Just a simple example of using ??

According to MDN it is the fifth most used operator directly lower than || and directly higher than the conditional ternary operator. I was surprised at this as I've seen ternaries used a lot, but. have only just discovered ??

Here is a typical use case scenario

instead of

let name = itemName !== undefined ? itemName : null

use

let name = itemName ?? null

for the same result.

More from this blog

jaxtrax

11 posts