Nullish Coalescing
Nullish Coalescing operator was introduced in ES6 2020.
this operator is used with the double question mark ??
it only works with nullish values, nullish values are (null and undefined) and ignore falsy value like (zero and empty string) 0 and " "
in some cases we would not like to ignore the falsy value, in such cases, Nullish Coalescing operator comes into the picture.
without nullish operator example 1 :
let i = 0;
console.log(i || 10) // result : 10
with nullish operator example 2 :
let i = 0;
console.log(i ?? 10) // result : 0
MERN Stack | ReactJs/NextJs/Gatsby/Sveltkit | Software Engineer
2 年Good job Muhammad Ahmad