double question mark js code example
Example 1: double question mark javascript
0 ?? "other"
false ?? "other"
null ?? "other"
undefined ?? "other"
Example 2: double question mark in js
const foo = null ?? 'default string';
console.log(foo);
const baz = 0 ?? 42;
console.log(baz);
Example 3: javascript double question mark
let a = null;
const b = a ?? -1;
console.log(b);
let a = 9;
const b = a ?? -1;
console.log(b);
Example 4: 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' ;