nullish coalescing operator not working code example
Example 1: nullish coalesing
Expression:
Left ?? Right
if left is null or undefined , then Right will be the value
const a = '' ;
const b = undefined;
const c = a ?? 'default' ;
const d = b ?? 'default' ;
Example 2: nullish-coalescing-operator
null || undefined ?? "foo";
true || undefined ?? "foo";
Example 3: nullish-coalescing-operator
let foo = { someFooProp: "hi" };
console.log(foo.someFooProp?.toUpperCase() ?? "not available");
console.log(foo.someBarProp?.toUpperCase() ?? "not available");