← All tutorials

GoCareerGo Tutorials

JavaScript Tutorial

Variables to closures, promises, the DOM and OOP — a complete JS reference.

Nullish Coalescing (??)

Returns the right-hand value ONLY when the left-hand value is null or undefined — unlike || which also triggers on 0, '' and false.

const count = 0;
count || 10;  // 10 — WRONG if 0 is a valid value!
count ?? 10;  // 0  — correct, 0 is not nullish
Tip

Use this exact 0-vs-empty-string example — it's the classic reason ?? was added to the language.