javascript / beginner
Snippet
Precise Defaults with Nullish Coalescing
The nullish coalescing operator (??) is a logical operator that returns its right-hand side operand when its left-hand side operand is null or undefined.
snippet.js
1
const score = game.points ?? 0;
nextjs
Breakdown
1
game.points ??
Checks if points is strictly null or undefined.
2
0
The fallback value used only if the left side is missing.