論理積 (&&)　Null 合体演算子 (??)　論理和 (||)　条件 (三項) 演算子

よく使う癖に挙動を覚えてなくて毎回確認してるのでリストにして置いておこうという考えで列挙
他にも便利なのあれば教えて欲しいです

~~~ts
if(何かの条件)=>{
return;
}
// ↑の条件に当てはまらない場合に実行したい処理をつらつらと下に書いていく
~~~
上記の書き方を他にないかなと思ってるんですが先に関数定義して下記をケースバイケースがいいんでしょうか？
~~~ts
const sample=()=>{実行したい処理}
何かの条件&&sample()
何かの条件||sample()
何かの条件??sample()
~~~


##  条件で関数実行のメモ
~~~ts
//適当な関数を用意
const anyMthod = () => {
  console.log("do anyMthod");
};
~~~


## [論理積 (&&)](https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Operators/Logical_AND)
~~~ts
console.log(`undefined && anyMthod()は`, undefined && anyMthod());
// undefined && anyMthod()は undefined
console.log(`0 && anyMthod()は`, 0 && anyMthod());
// 0 && anyMthod()は 0 do anyMthod
console.log(`1 && anyMthod()は`, 1 && anyMthod());
// 1 && anyMthod()は undefined
console.log(`null && anyMthod()は`, null && anyMthod());
// null && anyMthod()は null
console.log(`"" && anyMthod()は`, "" && anyMthod());
// "" && anyMthod()は "" do anyMthod //""が空白になってしまうから””と書き足してます
console.log(`"STR" && anyMthod()は`, "STR" && anyMthod());
// "STR" && anyMthod()は undefined do anyMthod
console.log(`[] && anyMthod()は`, [] && anyMthod());
// [] && anyMthod()は undefined do anyMthod
console.log(`["1"] && anyMthod()は`, ["1"] && anyMthod());
// ["1"] && anyMthod()は undefined do anyMthod
~~~


## [論理和 (||)](https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Operators/Logical_OR)
~~~ts
console.log("undefined || anyMthod()は", undefined || anyMthod());
// do anyMthod
// undefined || anyMthod()は undefined
console.log("0 || anyMthod()は", 0 || anyMthod());
// do anyMthod
// 0 || anyMthod()は undefined
console.log("1 || anyMthod()は", 1 || anyMthod());
// 1 || anyMthod()は 1
console.log("null || anyMthod()は", null || anyMthod());
// do anyMthod
// null || anyMthod()は undefined
console.log(`"" || anyMthod()は`, "" || anyMthod());
// do anyMthod
// "" || anyMthod()は undefined
console.log(`"STR" || anyMthod()は`, "STR" || anyMthod());
// "STR" || anyMthod()は STR
console.log(`[] || anyMthod()は`, [] || anyMthod());
// [] || anyMthod()は []
console.log(`["1"] || anyMthod()は`, ["1"] || anyMthod());
// ["1"] || anyMthod()は [ '1' ]
~~~


## [Null 合体演算子 (??)](https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Operators/Nullish_coalescing)
~~~ts
console.log("undefined ?? anyMthod()は", undefined ?? anyMthod());
// do anyMthod
// undefined ?? anyMthod()は undefined
console.log("0 ?? anyMthod()は", 0 ?? anyMthod());
// 0 ?? anyMthod()は 0
console.log("1 ?? anyMthod()は", 1 ?? anyMthod());
// 1 ?? anyMthod()は 1
console.log("null ?? anyMthod()は", null ?? anyMthod()); //特殊っぽい　先にdo anyMthodが表示されたあとundeinedが出る
// do anyMthod
// null ?? anyMthod()は undefined
console.log(`"" ?? anyMthod()は`, "" ?? anyMthod());
// "" ?? anyMthod()は
console.log(`"STR" ?? anyMthod()は`, "STR" ?? anyMthod());
// "STR" ?? anyMthod()は STR
console.log(`[] ?? anyMthod()は`, [] ?? anyMthod());
// [] ?? anyMthod()は []
console.log(`["1"] ?? anyMthod()は`, ["1"] ?? anyMthod());
// ["1"] ?? anyMthod()は [ '1' ]
~~~


## [条件 (三項) 演算子](https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Operators/Conditional_Operator)
~~~ts
console.log("undefined ? anyMthod()は", undefined ? anyMthod() : "OTHER");
// undefined ? anyMthod()は OTHER
console.log("0 ? anyMthod()は", 0 ? anyMthod() : "OTHER");
// 0 ? anyMthod()は OTHER
console.log("1 ? anyMthod()は", 1 ? anyMthod() : "OTHER");
// do anyMthod
// 1 ? anyMthod()は undefined
console.log("null ? anyMthod()は", null ? anyMthod() : "OTHER"); //特殊っぽい　先にdo anyMthodが表示されたあとundeinedが出る
// null ? anyMthod()は OTHER
console.log(`"" ? anyMthod()は`, "" ? anyMthod() : "OTHER");
// "" ? anyMthod()は OTHER
console.log(`"STR" ? anyMthod()は`, "STR" ? anyMthod() : "OTHER");
// do anyMthod
// "STR" ? anyMthod()は undefined
console.log(`[] ? anyMthod()は`, [] ? anyMthod() : "OTHER");
// do anyMthod
// [] ? anyMthod()は undefined
console.log(`["1"] ? anyMthod()は`, ["1"] ? anyMthod() : "OTHER");
// do anyMthod
// ["1"] ? anyMthod()は undefined
~~~