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.

Required fields*

4
  • 2
    sorry, you were all very fast in answering. Your first approach is also a case that i want to avoid. Consider that i have huge object with 5 to 15 levels of nesting. Commented May 22, 2014 at 14:05
  • 1
    You don't have a lot of options here. (1) property checking, manually, or with CoffeeScript, (2) try/catch. If you have an object with 15 levels of nesting and its property may be absent at any level, then I'd think you have some sub-optimal design patterns with you application. Commented May 22, 2014 at 14:14
  • 1
    It's an example. I want a way to cover that scenario. I obviously would avoid 15 levels of nesting but what if an old server-side application just does it that way and i have to deal with it? That's why i wanted to cover that scenario Commented May 22, 2014 at 14:15
  • 4
    .? is called the optional chaining operator. The nullish coalescing operator` (??) is very different and more similar to the OR operator (||). developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/…. Commented Jul 15, 2021 at 10:50