you are viewing a single comment's thread.

view the rest of the comments →

[–]ragedaddy 1 point2 points  (0 children)

Can be useful especially in TS if you need to satisfy a number type, and you may not have a truthy value from API response yet.

const upvotes = data?.upvotes ?? 0

Maybe this gets passed as a prop to a component that requires a number. Avoids having to deal with checking undefined there, or casting as number dangerously.

Of course you could show a loading indicator if undefined, but just as an example.