Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

4
  • 7
    This answer needs more upvotes. Nullish Coalescing Operator is now in stage 4.
    – Yerke
    Commented Jun 8, 2020 at 8:15
  • 3
    a && a.b && a.c should be a && a.b && a.b.c. I can't edit that in myself because it's not a big enough change for SO to accept and I don't want to do the "change inconsequential things to make it to 6 characters" thing.
    – Emily
    Commented Aug 20, 2020 at 3:43
  • You could add the way to do this with the [] syntax - from developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/… , all of these are possible: obj.val?.prop obj.val?.[expr] obj.arr?.[index] obj.func?.(args) Commented Nov 19, 2020 at 7:01
  • String I tried this in the developer tools and one would have expected the result for "const result = a?.b?.c ?? 'Some other value';" to be "Some other value" since I haven't defined "a" but it just throws an "Uncaught ReferenceError: a is not defined". "Is not defined" = undefined right?
    – Jacques
    Commented Jul 20, 2022 at 13:38