1

here's what the purpose of using ??

//Similar to || but only returns the right-hand operand if the left-hand is null or undefined
0 ?? "other" // 0
false ?? "other" // false
null ?? "other" // "other"
undefined ?? "other" // "other"

but I normally use &&, so what's the difference?

  • 1
    Relevant: [When should I use ?? (nullish coalescing) vs || (logical OR)?](https://stackoverflow.com/q/61480993) Overall, the sentiment is the same - do you want to handle *only* `null` and `undefined` or also other falsy values. – VLAZ Oct 16 '20 at 08:10
  • @VLAZ I'm asking `??` vs `&&` – Sandra Anderson Oct 16 '20 at 08:15
  • Again, do you want to handle all falsy values or only `null` and `undefined`? Because that's what the difference is. – VLAZ Oct 16 '20 at 08:16
  • @SandraAnderson, I [specifically answered](https://stackoverflow.com/a/70143185/8910547) your question about `??` vs `&&` :) – Inigo Nov 28 '21 at 12:02

0 Answers0