المعرفة:: JavaScript
الحالة:: ملاحظة_مؤرشفة
المراجع:: The Complete JavaScript Course 2022 From Zero to Expert


  • Introduced in ES2020.
  • It works with the concept of nullish values (null/undefined) instead of fasly values.
  • Values of 0, '', or false are NOT nullish values, but they are falsy.
restaurant.numGuests = 0;  
const guests1 = restaurant.numGuests || 10;  
console.log(guests1); // 10  
  
// Nullish: null and undefined (NOT 0, false or '')  
const guestCorrect = restaurant.numGuests ?? 10;  
console.log(guestCorrect); // 0