Answers for "Nullish Coalescing"

3

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' ; // will give c =''
const d = b ?? 'default' ; // wil give d = 'default'
Posted by: Guest on October-18-2020
0

nullish-coalescing-operator

let foo = { someFooProp: "hi" };

console.log(foo.someFooProp?.toUpperCase() ?? "not available"); // "HI"
console.log(foo.someBarProp?.toUpperCase() ?? "not available"); // "not available"
Posted by: Guest on January-06-2021
0

logical nullish operator javascript

function config(options) {
  options.duration ??= 100;
  options.speed ??= 25;
  return options;
}

config({ duration: 125 }); // { duration: 125, speed: 25 }
config({}); // { duration: 100, speed: 25 }
Posted by: Guest on January-05-2021
0

nullish-coalescing-operator

null || undefined ?? "foo"; // raises a SyntaxError
true || undefined ?? "foo"; // raises a SyntaxError
Posted by: Guest on January-06-2021
0

Nullish Coalescing

let x = foo ?? bar(); // return foo if it's not null or undefined otherwise calculate bar
Posted by: Guest on June-04-2021

Code answers related to "TypeScript"

Browse Popular Code Answers by Language