I am trying to use Logical AND &&
and Nullish coalescing operator ??
operators for the conditional rendering of variables/values.
But for some reason, I am unclear about the usage of both of these operators and how they work.
Please explain the difference between both of these and when should we use any of those instead of if
statement.
/* -------------------- ?? operator -------------------- */
const foo = null ?? '?? default string';
console.log(foo);
const baz = 0 ?? 10;
console.log(baz);
/* -------------------- && operator -------------------- */
const foo_1 = null && '&& default string';
console.log(foo_1);
const baz_1 = 0 && 20;
console.log(baz_1);