How to use logical OR assignment (||=) operator in Node.js

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 ||= 'node.js';
  
console.log(s);
  
    
      
      
/*
run:

node.js
      
*/

 



answered Dec 14, 2021 by avibootz

Related questions

1 answer 266 views
4 answers 790 views
2 answers 458 views
2 answers 422 views
1 answer 247 views
2 answers 343 views
...