0

In Javascript, if I'm trying to return an object property a.b, it will throw an error if a doesn't exist, so I have to first check if a exists and then return a.b. This becomes cumbersome if it's deeply nested, like a.b.c.d.e having to check for a, a.b, a.b.c, and a.b.c.d. Is there an operator that will automatically check if a exists and if so return a.b?

gkeenley
  • 6,088
  • 8
  • 54
  • 129
  • 9
    [Optional chaining](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Optional_chaining) – Pointy Jan 17 '23 at 14:27

0 Answers0