How to use logical OR assignment (||=) operator in TypeScript

2 Answers

0 votes
let a = 0;
a ||= 3;
console.log(a);

const b = 0;
//b ||= 8; // invalid assignment to const 'b' 

const c = undefined;
//c ||= 55; // invalid assignment to const 'c' 

 
   
     
     
/*
run:
     
3
     
*/

 



answered Dec 14, 2021 by avibootz
0 votes
let s = '';
 
s ||= 'typescript';
 
console.log(s);
 
   
     
     
/*
run:
     
"typescript"
     
*/

 



answered Dec 14, 2021 by avibootz

Related questions

1 answer 184 views
2 answers 235 views
2 answers 309 views
4 answers 307 views
1 answer 175 views
...