[JavaScript]オプショナルチェーン備忘録

1

const tmp = {name:"abc"};
console.log(tmp.address?.length);
undefined

 
 

2

const tmp = {name:"abc"};
console.log(tmp.address?.length+tmp.city?.length);
NaN

 
 

3

const tmp = {name:"abc"};
console.log(tmp.address?.length+tmp.city?.length > 4);
false

 
 

4

const tmp = {name:"abc"};
console.log(tmp.address?.length+tmp.city?.length == 0);
false

 
 

5

const tmp = {name:""};
console.log(tmp.name?.length+tmp.city?.length <= 1);
false

 
 

6

const tmp = {name:""};
console.log(tmp.name?.length <= 1);
true