Skip to guide content
[js] recap
Chapter 1 · Fundamentals Nullish coalescing operator

1.9

Nullish coalescing operator

Examples with a Run button are editable. Underlined terms open a short definition.

Nullish Coalescing Operator

//  Nullish Coalescing Operator
restaurant.numGuest = 0;
const guests = restaurant.numGuest || 10;
console.log(guests);
// Nullish: null and undefuned (NOT 0 and "")
const guestCorrect = restaurant.numGuest ?? 10;
console.log(guestCorrect);

Your last opened chapter is saved in this browser when local storage is available.

Discuss this section

Questions, corrections or a better example? Comments use GitHub Discussions.