The nullish coalescing operator ( ?? ) is a logical operator that returns its right-hand side operand when its left-hand side operand is null or undefined , and otherwise returns its left-hand side operand
//nullish coalescing operator in js
Expression:
Left ?? Right
if left is null or undefined , then Right will be the value
let value = null ?? "Oops.. null or undefined";
console.log(value) //Oops.. null or undefined
value = undefined ?? "Oops.. null or undefined";
console.log(value) //Oops.. null or undefined
value = 25 ?? "Oops.. null or undefined";
console.log(value) // 25
value = "" ?? "Oops.. null or undefined";
console.log(value) // ""
The OR operator || uses the right value if left is falsy
(e.g. "" or 0 or false), while the nullish coalescing operator ?? uses
the right value if left is null or undefined.