Nullish coalescing operator (??)
returns its right-hand side operand when its left-hand side operand is null or undefined,
and otherwise returns its left-hand side operand.
const foo = null ?? 'default string';
console.log(foo);
// expected output: "default string" because left hand side is null.
const baz = 0 ?? 42;
console.log(baz);
// expected output: 0 , because left hand side ( 0 ) is not null or undefinded.
//Similar to || but only returns the right-hand operand if the left-hand is null or undefined
0 ?? "other" // 0
false ?? "other" // false
null ?? "other" // "other"
undefined ?? "other" // "other"
let a = null;
const b = a ?? -1; // Same as b = ( a != null ? a : -1 );
console.log(b); // output: -1
//OR IF
let a = 9;
const b = a ?? -1;
console.log(b); // output: 9
//PS.,VERY CLOSE TO '||' OPERATION IN FUNCTION, BY NOT THE SAME
b = a ?? -1
_____________
if(a != null){
b = a;
}
else{
b = -1;
}