?? (ヌリッシュ合併) と || (論理和) の使い分けはいつ?
原題: When should I use ?? (nullish coalescing) vs || (logical OR)?
分析結果
- カテゴリ
- 経済
- 重要度
- 41
- トレンドスコア
- 9
- 要約
- 論理和演算子 || は左側の値が偽の場合に右側の値を使用しますが、ヌリッシュ合併演算子 ?? は左側の値が null または undefined の場合に右側の値を使用します。これらの演算子は、最初の値が無効な場合にデフォルト値を提供するためによく使用されます。
- キーワード
The OR operator || uses the right value if left is falsy, while the nullish coalescing operator ?? uses the right value if left is null or undefined. These operators are often used to provide a default value if the first one is missing.