Global Trend Radar
Web: stackoverflow.com US web_search 2026-05-01 02:01

JavaScriptにおける||と??演算子の違い

原題: javascript - Difference between || and ?? operators - Stack Overflow

元記事を開く →

分析結果

カテゴリ
経済
重要度
41
トレンドスコア
9
要約
JavaScriptでは、??(ヌル合体演算子)と||(論理OR演算子)は異なる動作をします。??は左側の値がnullまたはundefinedの場合に右側の値を返しますが、||は左側の値がfalsy(false、0、''、null、undefined、NaN)であれば右側の値を返します。例えば、const a = {}; const b = a.name ?? 'varun 1'は'b'に'varun 1'を代入し、const d = a.name || 'varun 2'は'd'に'varun 2'を代入します。
キーワード
What is the difference between ?? and || in JS const a = {} const b = a.name ?? 'varun 1' console.log(b) const d = a.name || 'varun 2' console.log(d) In the above code they both work ...

類似記事(ベクトル近傍)