javascript double question mark 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: logical nullish operator javascript
function config(options) {
options.duration ??= 100;
options.speed ??= 25;
return options;
}
config({ duration: 125 });
config({});