Null Coalescing Operator in React JS / Typescript

We have a null-coalescing operator in .NET, and we can use as shown below

string postal_code = address?.postal_code;

Can the same thing be done in React JS?

What I found, how can we do with the && Operator

in address.ts file

string postal_code = address && address.postal_code;

I need a .net function in typescript with JS response, is this possible?

sort of:

string postal_code = address?.postal_code // I am getting the error in this line if I try to use like .NET
+4
source share
2 answers

This is the proposed feature in TypeScript under the legendary Problem 16

TypeScript , ECMAScript , TypeScript - , .

:

  • Null Propagation
  • Null Coalesce
+2

JavaScript ( TypeScript, , JavaScript). JavaScript null -coalescing, 1 .

&& :

let postal_code = address && address.postal_code;

address - null ( #), postal_code ; address.postal_code.


ΒΉ : 0, "", NaN, null, undefined , , false.

0

Source: https://habr.com/ru/post/1696244/


All Articles