stay TypeScript In language , There are two situations where question marks appear : use ?: To represent optional properties ; use ?? Judge the null value of the variable .

The first situation is 《TypeScript Interface properties 》 I've already introduced , I won't repeat , This article mainly talks about the double question mark operator , I hope that's helpful .

const country = myCountry ?? 'CHINA';

When myCountry by null or undefined when ,country To be an assignment :CHINA, Otherwise, it is assigned as myCountry A variable's value .

It should be noted that : The double question mark operator has the property of short circuit , in other words :

a() ?? b() 

once a() Function return value is not null or undefined , No more b() function .